Change EventQueue implementation to reduce allocation churn of Queue buffers
Categories
(Core :: XPCOM, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox72 | --- | fixed |
People
(Reporter: jesup, Assigned: jesup)
References
Details
(Whiteboard: [memshrink:p1])
Attachments
(1 file)
EventQueue's internal use of mozilla::Queue can waste memory for most threads, and can cause intermittent allocations (every 256 events).
Switching to an implementation were the first buffer is treated as a circular buffer until it's full, at which point instead of allocating a solitary larger buffer we allocate another buffer, and release the first buffer when it drains. At that point, the second buffer ('page') -- if it's the last buffer -- becomes a semi-circular buffer.
This allows for the common case of secondary threads that rarely if ever have more than a few events queued can simply reuse a single (smaller) buffer, and just keep circular buffering. This avoids allocator traffic.
Alternative idea I need to get out of my head, just in case the first-buffer-is-circular is a pain to implement:
Keep one emptied buffer and re-use it next time a new page is needed.
In the ideal case, it means the queue will only ever allocate two buffers and will keep swapping between them.
This gut-feels simpler, at the cost of one extra allocation.
| Assignee | ||
Comment 2•6 years ago
|
||
Circular queue wasn't hard. I did think about what you mention, but it has it's own housekeeping work. The initial allocation wouldn't be an issue.
| Assignee | ||
Comment 3•6 years ago
|
||
This should avoid freeing and reallocating the buffer every N events, and
make it simpler to use smaller buffers, especially for non-MainThread queues.
Depends on D53910
Comment 5•6 years ago
|
||
| bugherder | ||
Updated•4 years ago
|
Description
•