Skip to content

[trees] improve tree initialization and rebuild performance#429

Merged
SlexAxton merged 2 commits intomainfrom
autoresearch/tree-core-benchmark-confidence-2026-03-26
Mar 26, 2026
Merged

[trees] improve tree initialization and rebuild performance#429
SlexAxton merged 2 commits intomainfrom
autoresearch/tree-core-benchmark-confidence-2026-03-26

Conversation

@SlexAxton
Copy link
Copy Markdown
Contributor

[trees] Optimize large tree initialization (~66% faster)

Two allocation-reduction optimizations that significantly reduce
initialization cost for large trees (93k linux kernel file set):

1. getItemsMeta traversal (tree/feature.ts):
   Replace per-node path.concat() and path.includes() with a reusable
   lineage stack + Set for circular-reference detection. Eliminates
   O(depth) array allocations and O(depth²) includes scans per node.

2. buildStaticInstance finalization (build-static-instance.ts):
   Replace Object.entries(definition) with for-in iteration to avoid
   allocating a key-value pair array on every instance method wiring
   call. This is the hot path during rebuildItemMeta for large trees.

Benchmark results (linux 93k file set, virtualized-card profile):
- Initialize median: ~201ms → ~69ms (-66%)
- Changed-state rebuild median: ~28ms → ~21ms (-25%)

All existing tests pass with identical behavior.

Add benchmarkTreeCorePrimitives.ts for realistic createTree/rebuildTree
measurement. Includes:

- Realistic init path: createTree → setMounted(true) → rebuildTree()
- Feature profiles: minimal, root-default, virtualized-card
- Rebuild modes: unchanged and expanded-copy (changed-state)
- Large-set focus: large-wide (8k), large-monorepo (2.4k), linux (93k)
- Deterministic checksum guards for drift detection
- JSON output with --compare baseline diffing
- Shared benchmark helpers extracted from fileListToTree benchmarks

Also refactors benchmarkFileListToTree.ts to use shared helpers and
adds expanded folder fixture support for realistic expansion state.
Two allocation-reduction optimizations that significantly reduce
initialization cost for large trees (93k linux kernel file set):

1. getItemsMeta traversal (tree/feature.ts):
   Replace per-node path.concat() and path.includes() with a reusable
   lineage stack + Set for circular-reference detection. Eliminates
   O(depth) array allocations and O(depth²) includes scans per node.

2. buildStaticInstance finalization (build-static-instance.ts):
   Replace Object.entries(definition) with for-in iteration to avoid
   allocating a key-value pair array on every instance method wiring
   call. This is the hot path during rebuildItemMeta for large trees.

Benchmark results (linux 93k file set, virtualized-card profile):
- Initialize median: ~201ms → ~69ms (-66%)
- Changed-state rebuild median: ~28ms → ~21ms (-25%)

All existing tests pass with identical behavior.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierrejs-diff-demo Ready Ready Preview Mar 26, 2026 6:46pm
pierrejs-docs Ready Ready Preview Mar 26, 2026 6:46pm

Request Review

@SlexAxton SlexAxton merged commit d7db28e into main Mar 26, 2026
8 checks passed
@SlexAxton SlexAxton deleted the autoresearch/tree-core-benchmark-confidence-2026-03-26 branch March 26, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant