Closed Bug 1976826 Opened 1 year ago Closed 1 year ago

Replace use of EncodedSize with bitmap in buffer allocator

Categories

(Core :: JavaScript: GC, task, P1)

task

Tracking

()

RESOLVED FIXED
143 Branch
Tracking Status
firefox143 --- fixed

People

(Reporter: jonco, Assigned: jonco)

References

(Blocks 1 open bug)

Details

Attachments

(3 external files, 2 obsolete files)

EncodedSize was added to represent a buffer size in a more compact way so we didn't have to use more than one byte per possible allocation start in a chunk. However I saw memset showing up in some benchmarks from clearing the size array when allocating small buffers in chunks with the changes in bug 1973033.

I realized that, clever though EncodedSize was, it's more efficient to store a bitmap of the end position of allocations. This is slightly less efficient when looking up the size but that happens rarely outside of sweeping. This has another advantage too as it means we can support allocations that are any multiple of the granularity so it's less restrictive that using EncodedSize.

Replacing the encoding size with a bitmap reduces the size of BufferChunk header by 192 bytes, nearly halving its size.

This change also opens the door to future sweeping optimisations where we can find free regions by using bitmap operations instead of iterating through every allocation.

Refactor AllocIter into a more general purpose BitSetIter which we can use for
our other bitmaps.

We have a bunch of these bitmaps were each bit set corresponds to a location in
memory. This adds a template class to make an iterator over these locations out
of a bitmap iterator.

The new bitmap has a bit set corresponding the the byte after the end of each
allocation, except if it abuts the end of the chunk.

Reading the current allocation size is now a race for allocations in chunks
that are currently being swept, and this affects realloc operations which need
to know how much data to copy even if the chunk is being swept. One option is
to make allocEndBitmap atomic, but it's simpler to pass the current allocation
size in since it's always known.

This can also now race with sweeping so don't allow it. We only use this for
debugging support so this doesn't have too much impact.

Severity: -- → N/A
Priority: -- → P1
Regressions: 1978767
Regressions: 1979584
Regressions: 1979525
Attachment #9500008 - Attachment is obsolete: true
Attachment #9500007 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: