Closed Bug 1597601 Opened 6 years ago Closed 6 years ago

Change EventQueue implementation to reduce allocation churn of Queue buffers

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla72
Performance Impact low
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.

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.

Blocks: 1597728

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

Pushed by rjesup@wgate.com: https://hg.mozilla.org/integration/autoland/rev/69ebf8af42a5 Make event Queues use the first buffer as a circular buffer r=froydnj
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla72
Performance Impact: --- → P3
Whiteboard: [memshrink:p1][qf:p3:responsivenes] → [memshrink:p1]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: