Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
During split operations, avoid redundant recursive split checks on each child insert. Use insert_without_check for child insertions, then check both children for splits once after all entries are distributed.
Increase SPLIT_COUNT to avoid costly splitting during data ingestion. Add optimize() to recursively distribute and rebalance after ingestion, and for_each_in_range_optimize that lazily optimizes subtrees during range queries. Called when the trace reader pauses for more data.
…memory usage Co-Authored-By: Claude <noreply@anthropic.com>
Change for_each_in_range_ref to use inclusive comparisons so entries exactly at range boundaries are not skipped.
Contributor
Tests Passed |
b920c88 to
e0a7b48
Compare
mischnic
reviewed
Apr 17, 2026
…r variants Co-Authored-By: Claude <noreply@anthropic.com>
mischnic
approved these changes
Apr 17, 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.
What?
Optimize the
SelfTimeTreedata structure in the Turbopack trace server for better performance and lower memory usage when loading large trace files, and fix a correctness bug in range queries.Why?
Two issues were identified:
Performance: The tree was splitting and rebalancing on every insert during bulk loading, and each
distribute_entriescall recursively triggered further split checks per entry, creating significant overhead.Correctness: Range query boundary conditions used exclusive comparisons (
</>), incorrectly excluding entries that touched the exact start or end timestamp of the queried range.How?
Performance optimizations:
Batch split checks: Add
insert_without_checkfor inserting entries without triggering a split check per entry. Indistribute_entries, entries are moved to children usinginsert_without_check, andcheck_for_splitis called once per child after all entries are distributed (rather than once per entry).Lazy optimization with memory reclamation: Add an
optimize()method and afor_each_in_range_optimize()traversal method that distribute and rebalance nodes lazily:store.optimize()is called when the reader reaches end-of-data (before waiting for more), doing a bulk pass to properly structure the tree after initial load. After distributing entries to children, each node callsshrink_to_fit()on its entries vec to release excess capacity.for_each_in_range_optimize()distributes and rebalances each node it visits, so query paths are progressively optimized during normal use.Fix
rebalance()bug:check_for_split()was incorrectly called after merging subtrees during rebalance — replaced withdistribute_entries()since the node already has children and needs redistribution, not a fresh split.Correctness fix:
All range boundary comparisons in
for_each_in_range,for_each_in_range_optimize, andlookup_range_countupdated from exclusive (</>) to inclusive (<=/>=), ensuring entries with timestamps exactly equal to the range endpoints are included in results.