Repository navigation
Conversation
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
ZeroedLayout returns an empty bitmap with the source's keys and, per key, an empty container of the source's size and type at its position in the source, so OR-ing a subset of the source into it never grows it. The keys node is resized to one spare slot whatever the source had, and every container offset shifts by the change in its size. Dead space is kept, not repacked. Only the keys node and the container headers are written. ZeroedLayoutToBuf and InitZeroedLayoutToBuf build into a buffer obtained from get, on CompactedToBuf's terms: get is called once with the exact size, and the buffer is adopted at its full capacity and may be dirty, so they also clear bitmap payloads. Array payloads and dead space keep their old bytes, since nothing reads them. Sizing takes the source's length and keys alone, with no pass over its containers. The WithHeadroom variants spend the buffer's surplus on extra key slots as CompactedToBufWithHeadroom does, estimating new containers from the source's own, so values ORed in at new keys after the last neither expand the keys node nor reallocate the data. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
CloneToBufWithHeadroom and InitCloneToBufWithHeadroom clone into a buffer obtained from get, on CompactedToBufWithHeadroom's terms: the surplus past the requested size buys key slots and leaves the rest as tail room, so values ORed in at new keys after the last neither expand the keys node nor reallocate the data. They share the zeroed layout's buffer step and keys writer. The keys node is resized to the source's keys plus one spare slot and the extra slots, dropping any spare slots the source had, and every offset shifts by the change in its size. The containers then follow in a single copy, each keeping its position, size and type, dead space included, so the clone matches the source container for container. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
aliszka
force-pushed
the
feat/zeroed-layout
branch
from
October 27, 2026 09:39
a339d2c to
07aa085
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
ZeroedLayoutand its buffer variants, which build an empty bitmap shaped like a source, andCloneToBufWithHeadroom, which clones into a pooled buffer with room for new keys. Both families take their buffer fromgetonCompactedToBuf's terms.Motivation
A caller that repeatedly ORs subsets of a known bitmap into a scratch bitmap pays for growth on every round: a new container moves everything after it, and a new key past the keys node's capacity moves every container. Starting from an empty bitmap with the source's keys, container sizes and types avoids both, since nothing the subset brings needs room the layout lacks. A caller that instead starts from a copy of the source, and adds values at keys beyond its last one, needs the same headroom
CompactedToBufWithHeadroomgives, without compacting.Approach
The source's layout is kept, not rebuilt: containers keep their position, size and type, dead space included, and only the keys node is resized, to the source's keys plus one spare slot (plus whatever the headroom variants buy). Every offset shifts by the change in the keys node's size, which may be negative when the source had spare slots. That keeps sizing O(1), from the source's length and keys alone, and lets the clone copy all containers at once. Repacking would make the result smaller but costs a pass over the containers, and the zeroed layout would then no longer match the source container for container.
The zeroed builds write only the keys node and the container headers. A pooled buffer may be dirty, so bitmap payloads are cleared; array payloads and dead space keep their old bytes, because nothing reads past an array's cardinality.
Key areas for review
bitmap.go:writeShiftedKeys: the offset shift, including the negative case wrapping inuint64.bitmap_opt.go:shiftedKeysDst: sizing beforeget, headroom from the buffer's capacity after it.bitmap.go:writeZeroedContainers: which bytes of a dirty buffer are cleared, and why the rest are safe.Testing
TestZeroedLayoutandTestLayoutToBufbuild every variant from sources covering nil, empty, key 0 only, arrays, bitmaps, mixed, dead space, emptied containers, spare key slots and oversized capacity, from dirty buffers. They check onegetcall, the exact layout, and that OR-ing a subset back in keeps capacity, length and offsets.TestLayoutToBufWithHeadroomchecks that keys added after the last fit without moving any container except an overflowing last array.TestLayoutToBufContractcovers the panics and zero allocations for theInitvariants.BenchmarkZeroedLayoutcompares against cloning and clearing;BenchmarkCloneToBufWithHeadroomagainstCloneToBuf, each alone and followed by an OR of new keys.🤖 Generated with Claude Code