Closed Bug 423815 Opened 16 years ago Closed 16 years ago

JSArena code "thrashes" mallocated arenas

Categories

(Core :: JavaScript Engine, defect, P4)

defect

Tracking

()

RESOLVED DUPLICATE of bug 412866

People

(Reporter: moz, Assigned: moz)

References

Details

(Keywords: perf)

Attachments

(2 files, 2 obsolete files)

Allocating memory with malloc() is costly, and JSArena code does too much of it.  Worse, some of the SunSpider benchmarks repeatedly allocate and deallocate arenas, costing performance.

JSArenaPools should buffer one or more arenas, to avoid the unnecessary calls to malloc.
I have sloppy patch which yields a reproducible 6% speed increase on SunSpider.  It does the following:

Associate with each JSArenaPool a single free arena.  It is always an arena equal to the arenasize of the pool.  Before malloc is called when a new arena is needed, the pool's free arena is checked for suitability (which is likely).  If it's suitable, then the already-allocated arena is used.

When arenas are freed, one of them is selected to be the pool's free arena, if it does not already have one.

This solution will likely have negative effects on footprint, but those could be addressed in another bug.  I will investigate, and post a patch soon.
Flags: blocking1.9?
Priority: -- → P1
One can see the across-the-board speedup achieved by the sloppy patch, giving a total speedup of 6%.
Debug builds will produce deceptive results on a benchmark like this, you should use opt-only for your sunspider testing.
Attached patch Sloppy patch (obsolete) — Splinter Review
This patch adds an "arena buffering" feature to JSArenaPools.  Gets me 6% performance improvement on SunSpider on a debug build.  The patch's effects on memory footprint are still unknown.
Attachment #310430 - Flags: review?(crowder)
Please refresh your benchmark results in this and other bugs by running them against optimized shell builds.  I'll work on review after that.  For bugs like this, it would be nice to know differences in memory utilization (peak, malloc counts), as well.
Get me a try server build and I'll test on win/mac
Flags: tracking1.9+
Flags: blocking1.9?
Flags: blocking1.9-
(In reply to comment #6)
> Get me a try server build and I'll test on win/mac

I have no Try server access.
The patch from comment #4 appears to be in an invalid format, did you add or remove lines manually?  Can you regenerate the patch with cvs diff -up8?  I will launch a Try build as soon as it's up.
(In reply to comment #8)
> The patch from comment #4 appears to be in an invalid format, did you add or
> remove lines manually?  Can you regenerate the patch with cvs diff -up8?  I
> will launch a Try build as soon as it's up.

Yes, that's why I called it "the sloppy patch".  It was meant as a proof-of-concept only, to show what changes I made and what effect they had.  My only goal for the patch was to show that arena thrashing was occurring.  I'll upload a valid patch, now.
Attached patch Non-sloppy patch (obsolete) — Splinter Review
Attachment #310430 - Attachment is obsolete: true
Attachment #310430 - Flags: review?(crowder)
In my tests, the most recent patch produces a small slowdown on optimized shell SunSpider runs.  There is no speedup.  Presumably, in the tradeoff of "fewer mallocs" versus "smaller footprint", "fewer mallocs" lost.

I will instrument my build, collect memory stats, and investigate.

It is possible that the effects of this change on a debug build are positive because of arena clearing (JS_CLEAR_UNUSED, etc.).  On debug builds, we actually write to the entire arena before freeing it, setting all the bytes to 0xDA.  This is expensive to do.  So, reducing the number of times that we do it makes a substantial performance improvement.

That is why the performance effects are opposite on a debug build from an optimized build, I suspect.
Version: unspecified → Trunk
Depends on: 412866
Reducing the priority.  Bug 412866 is the likely culprit of the thrashing, and the solution there is better than the solution in this bug's patches.  I expect to eventually mark this bug a dup.
Priority: P1 → P4
No longer blocks: 421435
Attachment #310620 - Attachment is obsolete: true
Flags: tracking1.9+
Attached patch Final patch.Splinter Review
I have re-tested SunSpider performance on an optimized build of the js shell, using the attached patch.  Performance improves a negligible 0.1% for me.  So, I conclude that the arena thrashing was indeed caused by the other bug.  I will mark this a dup.
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: