Repository navigation
perf(workbench,filter): optimize filter result payload with SparseBitset and IdBitset - #894
Conversation
Benchmark & Capacity Reference DataTo quantify the performance and memory improvements of this change, benchmarks were conducted across wire payload serialization, frontend decoding, and in-memory filter operations for large datasets (1,000,000 items). 1. Wire Payload Size Comparison (1,000,000 Logs)Comparison between flat ID arrays (
2. Frontend Protobuf Deserialization Speed (1,000,000 Items)Benchmark comparing deserialization and conversion into frontend bitset structures:
3. Frontend In-Memory & Performance Benchmark (
|
| Metric (1,000,000 items) | Set<number> |
IdBitset (Uint32Array) |
Improvement (IdBitset vs Set) |
|---|---|---|---|
| Heap Memory Footprint | 38.75 MB | 6.20 MB | 84.0% less memory (raw buffer is only 125 KB) |
| Construction Time (500k items) | 55.61 ms | 2.30 ms | 24.2x faster |
Lookup .has(id) (1M lookups) |
64.80 ms | 6.38 ms | 10.2x faster |
Clone Time (.clone()) |
6.72 ms | 0.053 ms | 126.5x faster |
| Batch Deletion (10k items) | 45.92 ms | 0.41 ms | 110.7x faster |
There was a problem hiding this comment.
Code Review
This pull request replaces the array-based timeline and log ID filtering with a highly optimized, sparse bitset representation (SparseBitset) and a new FilterResultMode enum (supporting INCLUDE and EXCLUDE modes) to minimize payload size. On the backend, Go helper functions are introduced to build and encode these bitsets, while the frontend implements a high-performance IdBitset using Uint32Array to perform sub-millisecond bitwise operations. The review feedback recommends adding defensive checks in the Go bitset encoding to prevent potential panics, using modern slices.Sort instead of reflection-based sorting, and optimizing the frontend IdBitset decoding by utilizing a popcount helper and directly filling the typed array in fromSequential to eliminate loop overhead.
Summary
This PR optimizes the Workbench timeline and log filtering pipeline by replacing full ID list transfers (
[]uint32) and frontendSet<number>operations with compactSparseBitsetserialization and a custom high-performanceIdBitsetdata structure.Background & Motivation
Previously, the backend
FilterTimelineRPC returned explicit slices of all matchingtimeline_idsandlog_ids. On large inspection datasets (e.g. hundreds of thousands of logs and timelines), transferring repetitive arrays over gRPC resulted in substantial serialization overhead and network payload bloat. Furthermore, the frontend converted these arrays into native JavaScriptSet<number>instances, causing noticeable garbage collection overhead and memory churn during frequent filter queries.Solution Overview
workbench.proto): DefinedSparseBitset(indices,maskswith 32-bit words) andFilterResultMode(INCLUDE/EXCLUDE).pkg/server/workbench/bitset.go): Backend dynamically selects eitherINCLUDEmode (when matching count <= 50%) orEXCLUDEmode (when matching count > 50%) to minimize the wire size of the sparse bitset.IdBitseton Frontend (web/.../id-bitset.ts): ReplacedSet<number>inLogTimelineFilterContextwith a custom 32-bit typed array bitset supporting bitwise intersection (and), bitwise difference/inversion (not), value iterator generation, and fast sparse bitset decoding.TimelineView,BackendFilter, andCollapseTimelineFilterto operate directly onIdBitset.Key Changes
1. Protobuf Definitions (
proto/api/v1/workbench.proto)SparseBitsetmessage representing non-zero 32-bit bitmask blocks.FilterResultModeenum (INCLUDE,EXCLUDE).FilterResultto carrytimeline_mode,timeline_bitset,log_mode, andlog_bitset.2. Backend (
pkg/server/workbench/)BuildSparseBitsetandEncodeFilterResultBitsetinbitset.gowith full test coverage (bitset_test.go).FilterTimelineinfilter.goto encode filter results intoSparseBitsetbased on total timeline/log counts.pipeline_test.goto test sparse bitset decoding.3. Frontend (
web/src/app/)IdBitsetclass (store/domain/filter/id-bitset.ts) and comprehensive unit tests (id-bitset.spec.ts).LogTimelineFilterContextinstore/domain/filter/types.tsto useIdBitsetinstead ofSet<number>.WorkbenchClientServiceto decodeSparseBitsetintoIdBitset.BackendFilter,CollapseTimelineFilter, andTimelineViewto compute filter intersections using bitwise operations.Included Commits
feat(proto): update FilterResult with SparseBitset and FilterResultModefeat(backend): implement SparseBitset builder and update FilterTimeline in workbenchfeat(frontend): implement IdBitset and integrate SparseBitset with filter pipelineVerification
make test-go(All unit tests passed)make test-web(All 736 unit tests passed)make lint-go && make lint-web(Passed with 0 issues)make pre-commit(Formatted cleanly)