(protobuf) Fix EnumLookup hash-area sizing - #773
Open
pjfanning wants to merge 1 commit into
Open
Conversation
`EnumLookup.Big.construct()` called `findSize(byId.size())` on the line after `byId` was created and before it was populated, so the result was always `findSize(0)` == 8 regardless of enum size. Every protobuf enum therefore got an 8-slot primary + 4-slot secondary hash area. A 100-value enum pushed ~88 entries into the linearly-scanned spill area, and grew the backing arrays 4 slots at a time while building it. Sizing from `entries` gives 128 primary slots and 19 spills for the same enum. Correctness was never affected -- the spill scan finds everything -- but the cost is paid on every enum-valued field write. Adds a regression test, plus two package-private accessors on `EnumLookup.Big` so the hash-area sizing can be asserted. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Split out of #772.
byIdis created on the line above and populated in the loop below, so this is alwaysfindSize(0)== 8. Every protobuf enum, regardless of size, got an 8-slot primary + 4-slot secondary hash area. A 100-value enum pushed ~88 entries into the linearly-scanned spill area, and grew the backing arrays 4 slots at a time while building it.Sizing from
entriesinstead gives 128 primary slots and 19 spills for the same enum.Correctness was never affected — the spill scan finds everything — so this is purely lookup and construction cost, paid on every enum-valued field write.
Pre-dates the 2.x -> 3.x rename and is present on
2.21too; targeting3.xfor now, happy to redo against2.21and merge forward if you prefer.Test
EnumLookupTest— a 100-value enum resolves every entry by name and by index, and the primary hash area is 128 slots rather than 8. Needed two package-private accessors (hashArea(),spillCount()) onEnumLookup.Big.Full
protobufmodule test suite passes.🤖 Generated with Claude Code