Repository navigation
perf(workbench): pack CEL TrigramKey into uint64 and serialize StructYAMLs on-demand - #938
Merged
Merged
Conversation
…in favor of on-demand serialization
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
September 2, 2026 03:06
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the search indexing and evaluation pipeline by removing the pre-serialized StructYAMLs cache from SearchIndex and LogEvaluator, opting instead to serialize structs to YAML on-demand. Additionally, it optimizes the TrigramIndex by packing 3-rune trigrams into a 64-bit integer (TrigramKey) instead of using strings, which reduces memory usage and simplifies binary serialization. Feedback is provided regarding the instantiation of DirectYAMLSerializer on every call to resolveStructYAML, which defeats its internal schema caching; using a sync.Pool to reuse serializer instances is recommended to avoid significant CPU overhead and memory allocations.
… DirectYAMLSerializer
kyasbal
commented
Sep 2, 2026
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 CPU optimizations to Workbench index construction and CEL evaluation:
Pack Trigram into uint64
TrigramKey(pkg/server/workbench/cel):TrigramIndexwith a compactTrigramKey(uint64).0x000000to0x10FFFF). By packing 3 lowercase runes into a single 64-bit integer ((r0 << 42) | (r1 << 21) | r2), we eliminate heap allocations during trigram extraction, map lookups, and index merging across parallel workers.0x03, writing 8-byte uint64 values directly rather than length-prefixed strings.evalTrigramQueryto convert query terms toTrigramKeyfor candidate bitmap evaluation.Eliminate Pre-Serialized
StructYAMLsinSearchIndex(pkg/server/workbench):SearchIndexpre-serialized every interned struct body into a YAML string map (map[uint32]string), consuming significant heap memory (~2x the size ofInternPoolitself) and delaying workbench startup.StructYAMLswith on-demand serialization viakhifilev6model.DirectYAMLSerializerandwb.internPoolwhen needed (e.g., inReadStructYAMLs).BuildStructYAMLIndexWithProgressfrom workbench initialization, reducing indexing latency.InternPoolreference inSearchIndexto resolve structs and build indexes efficiently.Benchmark & Memory Impact
Running
BenchmarkMemory_InternPoolVsStructYAML(5,000 realistic unique Pod manifests):InternPool)StructYAMLscuts overall heap footprint by ~39% (~16.3 MB -> ~10.0 MB) during workbench initialization.Test Plan
make pre-commitmake test-goandmake test-webpkg/server/workbenchandpkg/server/workbench/cel