Repository navigation
perf(server): optimize server-side .khi file loading and timeline filtering - #903
Conversation
…tering - Introduce DirectYAMLSerializer for fast serialization of interned structs in InternPool. - Implement parallel chunk reader for binary .khi files. - Optimize timeline CEL filtering with fast bitset decoding.
There was a problem hiding this comment.
Code Review
This pull request introduces significant performance optimizations to the workbench and file parsing systems. Key changes include the addition of a DirectYAMLSerializer to serialize interned structs directly to YAML, parallel chunk decompression and parsing in NewFromReader, and refactoring the filter pipeline (FilterContext and various CEL filters) to use roaring.Bitmap instead of Go maps for timeline and log IDs. Review feedback highlights critical thread-safety issues in the new DirectYAMLSerializer due to a shared buffer, potential panics in LogCELFilter from nil bitmaps in parallel workers, and missing defensive nil checks on several nullable protobuf fields. Additionally, a minor performance optimization was suggested to avoid unnecessary string allocations during YAML scalar safety checks.
Summary
This PR optimizes server-side
.khifile loading and timeline filtering performance on the KHI backend.Background & Motivation
When opening large inspection files (e.g. 200,000+ logs, hundreds of megabytes), decoding interned structures and evaluating CEL filters on timeline logs incurred heavy CPU and memory overhead:
Key Changes
1. Direct YAML Serializer (
pkg/model/khifile/v6/direct_yaml.go)DirectYAMLSerializer, directly serializing interned structs and fields fromInternPoolinto YAML bytes without allocating intermediate generic map/struct representations.direct_yaml_test.go.2. Parallel Binary Chunk Reader (
pkg/server/workbench/reader.go).khireader with optimized chunked parallel reading and pooled decompression buffers.3. Timeline Bitset & CEL Filter Optimization (
pkg/server/workbench/)bitset.gofor compact timeline presence tracking.filter_log_cel.goandfilter_timeline_cel.goto directly leverage interned structures and fast evaluation paths.Verification
make test-gopassed (100%).make test-webpassed (762 tests).make lint-gopassed (0 issues).make pre-commitpassed.