Skip to content

perf: speed up build ID-finalization pipeline#165

Merged
uhyo merged 1 commit into
masterfrom
claude/issue-150-6jvacj
Jul 22, 2026
Merged

perf: speed up build ID-finalization pipeline#165
uhyo merged 1 commit into
masterfrom
claude/issue-150-6jvacj

Conversation

@uhyo

@uhyo uhyo commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Closes #150

Two small efficiency cleanups in the build ID-finalization pipeline, as described in the issue:

  • topologicalSort cycle detection (packages/static/src/build/dependencyGraph.ts): collecting cycle members used sorted.includes(node) inside a loop (O(n²)). It now checks membership against a Set of sorted nodes.
  • ID replacement (rscProcessor.ts and buildApp.ts): each content string previously got one replaceAll pass per mapped ID, i.e. O(components × mappings) full-string scans. Both call sites now share a new replaceIdsInContent helper (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, and pnpm test:run (110 tests) all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qtu57DrjTuQaGdKMtqSvyt


Generated by Claude Code

- 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
uhyo force-pushed the claude/issue-150-6jvacj branch from bb12f4a to 23d35bd Compare July 22, 2026 02:22
@uhyo
uhyo merged commit 60f42c3 into master Jul 22, 2026
2 checks passed
@uhyo
uhyo deleted the claude/issue-150-6jvacj branch July 22, 2026 02:43
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.

Minor perf cleanups in the build ID-finalization pipeline

2 participants