Skip to content

perf(web): cut 100k-path tree render cost and served shell bytes - #127

Merged
DontBlameMeDev merged 1 commit into
mainfrom
t3/fa76005d
Nov 20, 2026
Merged

DontBlameMeDev merged 1 commit into
mainfrom
t3/fa76005d

Conversation

@DontBlameMeDev

@DontBlameMeDev DontBlameMeDev commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

The 100,000-path listing render guard in test/tree-view.test.ts was failing on this host at 5,548 ms against its 5,000 ms budget. The same listing is read on every room event, and the generated shell was carrying 32 KB of comments a browser throws away.

This change derives the tree with one name index per directory and stores file children directly instead of allocating a leaf object and a child array for every path. A presence frame now compares the small row chrome and skips rebuilding the multi-megabyte rows key when nothing it draws changed, while still honoring the forced-rebuild sentinel. The build strips HTML comments and CSS comments inside <style> from the generated dist/*.html only; the source pages keep their comments for the page-contract tests.

Proof:

  • Baseline npm run test:ci: 34.03 s, 896/897 tests, failing draws the levels a person opened, not a row per path at 5,548 ms / 5,000 ms. After: 898/898 pass. npm test also 898/898 pass.
  • In-process A/B benchmark loading the HEAD and candidate grantLevels modules side by side over the same 100,000-path array (9 runs each, garbage collection between runs): median 472 ms before, 426 ms after (9.7% less CPU), with byte-identical output maps.
  • Repeated same-frame GrantTreeView.render() in the 100,000-path fixture: 5-7 ms CPU before, under 1 ms after. world.created stayed 9 for the ceiling render and 0 for the presence frame.
  • The new regression test at test/tree-view.test.ts:1601 fails on the first candidate ('the row is still dimmed after the drag ended') and passes after the review fix.
  • wc -c dist/index.html dist/404.html: 92,551 -> 60,599 B (-31,952 B, -34.5%) and 7,292 -> 6,979 B (-313 B). Total dist/ files: 18,797,338 -> 18,767,044 B.
  • npm run typecheck passes. scripts/ci-local.sh all passes end to end, including the byte-reproducible dist/ check and link check. Workspace contract check at the candidate commit: 4 comparisons, 0 drifted, 0 errors.

Scope decisions: src/bridge/ and src/engine/ are canonical copies checked against vscode_client, so no optimization there was landed. The sidebar's per-pointer-move storage write and the eager engine import were investigated but left alone: the first has a test that requires one write per move, and the second needs a wider import refactor with no measured win in this change.

Skipped checks: the live proof scripts need SELVAGE_SELVAGED and Chromium, and the container smoke needs Docker. Neither is part of scripts/ci-local.sh all.

Reviewed with review-loop: 2 rounds with opencode-go/hy4-flash-free. verdict: approved

Created with opencode-go/hy4-flash-free in Pi (T3 Code), including the read-only investigator and review subagents.

Summary by CodeRabbit

  • Bug Fixes
    • File rows now retain their position when a path also identifies a directory, and presence badges can refresh without rebuilding unchanged rows.
    • Ending a drag without dropping no longer dims the row or moves the file.
  • Chores
    • Generated HTML pages have comments removed during builds.

Derive the grant tree without a leaf object and child array per path, skip rebuilding the row key on unchanged presence frames, and strip comments from the generated shell.
Copilot AI balanced review requested due to automatic review settings November 20, 2026 02:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The build now transforms public HTML pages before writing them to dist. Browser tree code now tracks directory entries and render keys separately. A test verifies that ending a drag without dropping does not move or dim a file row.

Changes: Served HTML Shell

Layer / File(s) Summary
Transform public HTML shells
scripts/build.mjs
The build removes HTML comments and CSS comments inside <style> elements before writing public pages to dist. Script content remains untouched.

Browser Tree

Layer / File(s) Summary
Build and order directory entries
src/browser/tree.ts
Tree construction tracks names per directory and promotes an existing file entry to a directory when a path requires it. Directory-first ordering and code-unit name sorting remain in place.
Cache tree render keys
src/browser/tree-view.ts, test/tree-view.test.ts
Rendering tracks listing and row-chrome keys to refresh badges or rebuild rows. The test verifies that ending a drag without a drop does not request a move or leave the row dimmed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: Low · up to bf2a4

The change is mergeable with awareness that large listings containing many file-to-directory collisions can render more slowly. Removing the repeated sibling searches would preserve the intended performance improvement.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@DontBlameMeDev
DontBlameMeDev merged commit 2f34bb0 into main Nov 20, 2026
7 of 8 checks passed
@DontBlameMeDev
DontBlameMeDev deleted the t3/fa76005d branch November 20, 2026 02:11
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.

2 participants