Closed Bug 195385 Opened 21 years ago Closed 21 years ago

jsparse.c suggestion: avoid recursion in RecycleTree

Categories

(Core :: JavaScript Engine, enhancement, P1)

x86
All
enhancement

Tracking

()

VERIFIED FIXED
mozilla1.4alpha

People

(Reporter: user, Assigned: brendan)

Details

(Keywords: js1.5)

Attachments

(2 files, 1 obsolete file)

Currently RecycleTree uses recursion to flatten a parse subtree into a recycled
list. But this uncontrolled recursion that can trigger potentially a stack
overflow can be avoided if tree flattening will be delayed until the subtree
root is reused. 

To implement this, RecycleTree can simply append the subtree root to the
recycled tree and only when the root node will re-used, its direct children will
be recycled.

This setup will bring another advantages if the parser recycles more nodes then
it needs, since during recycling the children of unused subtree roots will not
be touched at all.
I tried to preserve the current assertion checks semantics and recycling debug
counting in RecycleTree with the patch, but I may miss something in this area.
Reassigning, and cc'ing Brendan for consideration of this patch -
Assignee: rogerl → khanson
Igor, great idea.  I took your patch and reduced old open-coded
JS_ARENA_ALLOCATE macro calls (my fault) further, to avoid both
ConsumeRecycledHead and its callers having to load tc->nodeList, and then do the
arena allocation if that list is empty.  I also fixed the METER_PARSENODES code
that lacked a pn-> in front of pn_count ;-).  Patch (diff -u and -wu) in a moment.

/be
Assignee: khanson → brendan
Priority: -- → P1
Target Milestone: --- → mozilla1.4alpha
Status: NEW → ASSIGNED
Keywords: js1.5
Attachment #115852 - Attachment is obsolete: true
For easier reviewing, but I'll request r=shaver on the last patch.

/be
Attachment #115947 - Flags: review?(shaver)
The patch passes the JS testsuite on both WinNT and Linux.
I ran it in both the debug and optimized JS shells.

No test regressions were observed -
Comment on attachment 115948 [details] [diff] [review]
diff -w version of last patch

I like it.  I'd like it more if we inlined RecycleNode, since it's so tiny, but
we don't have a good JS_INLINE to use, so I'll live.

r=shaver.
Attachment #115948 - Flags: review+
Comment on attachment 115947 [details] [diff] [review]
my take on Igor's patch

I meant to r+ this one, alas.
Attachment #115947 - Flags: review?(shaver) → review+
Inlining can blow your icache; I'll let compilers be brave about it, if not
smart (a static function whose address is not taken can be inlined everywhere
that it's called if the compiler thinks that wins).

I did make one more change: I eliminated the static forward prototype for
NewOrRecycledNode, by moving RecycleTree and NewOrRecycledNode up above the
latter's first caller, NewParseNode (where the static forward was).

Thanks again to Igor, and thanks to shaver for the review+ -- checked in.

/be
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Checkin verified; passes the JS testsuite on Linux and WinNT -
Status: RESOLVED → VERIFIED
Flags: testcase-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: