Considerable overhead from allocating temporary profiler buffer when capturing markers with stack
Categories
(Core :: Gecko Profiler, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox97 | --- | fixed |
People
(Reporter: bas.schouten, Assigned: mozbugz)
References
(Depends on 1 open bug, Blocks 4 open bugs)
Details
Attachments
(3 files)
We're seeing capturing markers with stack cause significant overhead due to memory allocation.
Example profiles:
https://share.firefox.dev/3FrP5rW
Assignee | ||
Comment 1•4 years ago
|
||
I believe this is due to the last allocation (that I know of) in markers, see some details in bug 1578792 comment 4. I'll copy your profiles there.
We use a ProfilerBufferChunkManagerSingle
in AddMarkerToBuffer
, and that allocates a chunk on the heap.
Ideally, we'd like to allocate this buffer on the stack, if there is enough space left -- that last part may be difficult to implement on all platform(?)
An alternative would be to have one or more pre-allocated buffers that could be used.
The best would be one per profiled thread, but that could chew quite a bit of memory if profiling lots of threads.
Otherwise a pool of available buffers, at some small synchronization cost, with the worst case being that they're all being used and block more markers.
Comment 2•4 years ago
|
||
(In reply to Gerald Squelart [:gerald] (he/him) from comment #1)
The best would be one per profiled thread, but that could chew quite a bit of memory if profiling lots of threads.
For the example profiles provided in comment 0, it seems only the main thread matters, so special casing it might make sense.
Assignee | ||
Comment 3•4 years ago
|
||
On it now.
I will add a main-thread path in AddMarkerToBuffer
using a single static buffer that's only allocated once, when needed by the very first main-thread marker.
And while working on this, I discovered/remembered that all ProfileBuffer
s allocated a chunk that was only really needed in some situations, so we can avoid this allocation in temporary ProfileBuffer
s like in AddMarkerToBuffer
; this will benefit all threads. 🎉
Assignee | ||
Comment 4•4 years ago
|
||
Some ProfileBuffers are temporary and don't actually need this allocation.
Assignee | ||
Comment 5•4 years ago
|
||
The resulting code should be the same. The factored lambda will be called in the next patch with a different chunked buffer.
Depends on D133723
Assignee | ||
Comment 6•4 years ago
|
||
The main thread is the busiest, so it benefits the most from having its own chunked buffer. This removes all but one allocation when capturing a marker stack on the main thread of each process.
Note: Further improvements are possible (e.g.: Pool of pre-allocated buffers, attempting to use a stack-based buffer, etc.), but they are more complex and will require more work in future bugs.
Depends on D133724
Comment 8•4 years ago
|
||
Backed out for causing xpcshell failures on ProfileBufferChunkManager.h
- Backout link
- Push with failures
- Failure Log
- Failure line: Assertion failure: !mUser, at /builds/worker/workspace/obj-build/dist/include/mozilla/ProfileBufferChunkManager.h:117
Assignee | ||
Comment 9•4 years ago
|
||
Thank you Cristian. Strange that I didn't catch that one in my Try. I'll investigate...
Assignee | ||
Comment 10•4 years ago
|
||
Oh, it's because I didn't run xpcshell tests! 😅
Comment 11•4 years ago
|
||
Comment 12•4 years ago
|
||
Backed out for causing assertion failures at ProfilerMarkers.cpp.
Backout link: https://hg.mozilla.org/integration/autoland/rev/e390c6bc407cfc2c4cd8a78ec50719487c1842fb
Push where failures started: https://hg.mozilla.org/integration/autoland/rev/e390c6bc407cfc2c4cd8a78ec50719487c1842fb
Failure log: https://treeherder.mozilla.org/logviewer?job_id=361496637&repo=autoland&lineNumber=47160
Comment 13•4 years ago
|
||
Assignee | ||
Updated•4 years ago
|
Comment 14•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/ce69ff8b2ab1
https://hg.mozilla.org/mozilla-central/rev/ec0aef0c5580
https://hg.mozilla.org/mozilla-central/rev/5bd128b532ea
Description
•