Repository navigation
perf(khifile): optimize InternPool memory retention, ID resolutions, and ToInternedStruct allocations - #935
Merged
Conversation
…derlying byte buffers
…nPool ID resolutions
…re proto allocation
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
September 2, 2026 00:26
Contributor
There was a problem hiding this comment.
Code Review
This pull request optimizes the InternPool by replacing several sync.Map lookups with slice-based index resolution protected by read-write mutexes. It also introduces a fast-path key computation (structKeyFromNodes) to avoid redundant protobuf allocations for already interned structs, and reuses static interned values for null and boolean types. The review feedback suggests further optimizing the slice-growing functions (storeString, storeFieldSet, and storeStruct) to avoid temporary slice allocations during growth, and simplifying the locking/unlocking flow in resolveStringFromID to reduce lock contention and nested conditions.
…lveStringFromID locking
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.
Description
This PR introduces memory and allocation optimizations to
khifilev6interning and struct conversion:Prevent pinning underlying byte buffers in
InternString:InternPool.InternString(e.g., extracted from largeprotojsonbyte buffers) could keep entire input buffers alive in memory.strings.Clonebefore storing in the pool to allow transient buffers to be garbage-collected.Replace
sync.Mapwith mutex-protected slices for ID resolutions inInternPool:sync.MapforidToStr,idToFieldSet, andidToStructwith dense slices ([]string,[][]uint32,[]*pb.InternedStruct) guarded bysync.RWMutex.Fast-path binary key computation in
ToInternedStruct:[]*pb.InternedValueand proto messages when a struct is already interned inInternPool.structKeyFromNodesto compute the cache key directly fromstructured.Nodevalues using a reusable byte buffer.bool(true/false) andnullinterned values.Test Plan
make pre-commitmake lint-goandmake test-gopkg/model/khifile/v6