perf: speed up build ID-finalization pipeline#165
Merged
Conversation
- topologicalSort: use a Set for cycle detection instead of O(n²) sorted.includes() scans - Replace per-mapping replaceAll passes with a single-pass alternation regex in a shared replaceIdsInContent helper, used by both rscProcessor and buildApp Closes #150 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qtu57DrjTuQaGdKMtqSvyt
uhyo
force-pushed
the
claude/issue-150-6jvacj
branch
from
July 22, 2026 02:22
bb12f4a to
23d35bd
Compare
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.
Closes #150
Two small efficiency cleanups in the build ID-finalization pipeline, as described in the issue:
topologicalSortcycle detection (packages/static/src/build/dependencyGraph.ts): collecting cycle members usedsorted.includes(node)inside a loop (O(n²)). It now checks membership against aSetof sorted nodes.rscProcessor.tsandbuildApp.ts): each content string previously got onereplaceAllpass per mapped ID, i.e. O(components × mappings) full-string scans. Both call sites now share a newreplaceIdsInContenthelper (packages/static/src/build/idReplacement.ts) that regex-escapes the mapped temp IDs, joins them into one alternation regex, and replaces everything in a single pass over the content. Identity mappings (cycle members that keep their temp IDs) are skipped, matching the previous behavior.Added unit tests for the new helper covering multiple IDs, repeated occurrences, identity mappings, regex-special characters in IDs, and no re-replacement of already-substituted output.
pnpm typecheck,pnpm lint,pnpm format:check, andpnpm test:run(110 tests) all pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01Qtu57DrjTuQaGdKMtqSvyt
Generated by Claude Code