Skip to content

perf: Replace regex captures with hand-written parsers in berry lockfile identifiers - #13776

Merged
anthonyshew merged 2 commits into
mainfrom
agents/performance-2026-08-19
Aug 19, 2026
Merged

anthonyshew merged 2 commits into
mainfrom
agents/performance-2026-08-19

Conversation

@vercel-gh-bot-2

Copy link
Copy Markdown
Contributor

Summary

Replaces the two hot regexes in crates/turborepo-lockfiles/src/berry/identifiers.rs (^(?:@([^/]+?)/)?([^@/]+)$ for Ident and ^(?:@([^/]+?)/)?([^@/]+?)(?:@(.+))$ for Descriptor/Locator) with exact hand-written parsers. On a yarn-berry monorepo these regexes run ~40–50k times per turbo run invocation: once per descriptor in every lockfile entry key during BerryLockfile construction, once per resolve_package call from the transitive-closure DP, and once per dependency inside every all_dependencies call. Cold-path regexes (from_patch_reference, patch_file, is_patch_builtin) are unchanged. Public API, error messages, and Cow::Borrowed lifetimes are unchanged.

  • Author model: anthropic/claude-fable-5
  • Reviewer model: openai/gpt-5.6-sol (gpt_performance_reviewer)

Hypothesis

Berry identifier parsing is a materially hot path (per-call regex capture extraction and its allocation) on large yarn-berry monorepos; replacing it with allocation-free manual parsing reduces end-to-end turbo run --dry=json wall time with zero behavior change.

Diagnostics that motivated it: instrumented span profile on cal.com showed resolve_package 45.5 ms/11,520 calls, all_dependencies 19.3 ms/3,812 calls, parse_lockfile 40.4 ms of a ~210 ms run; perf on a symbolized build showed regex_automata::dfa::onepass::DFA::try_search_slots_imp (8.0%) and Regex::captures_at (2.4%) as top leaves of a lockfile-only workload.

Methodology

  • Environment: Linux 6.18.40 x86_64, Intel Xeon @ 2.90 GHz, 2 vCPU, 4.2 GB RAM, THP=madvise, rustc 1.97.0-nightly (pinned nightly-2026-05-22), hyperfine 1.20.0 (official release, SHA-256 verified). Shared/noisy VM disclosed; mitigated with paired balanced blocks, medians, and bootstrap CIs.
  • Binaries: both built with cargo build --profile release-turborepo -p turbo. Baseline from clean checkout 37be819 (SHA-256 992fbd03…, 50,632,544 B); candidate from this diff (SHA-256 77d54a01…, 50,630,752 B; −1,792 B). Both preserved outside the checkout; all evidence fingerprints these exact binaries.
  • Workload: cal.com @ 176037d0afbe572f870a3c702985e7cd83fe6c0c (yarn berry, 1.5 MB yarn.lock, 3,935 entries), detached and immutable. Command: turbo run build --dry=json --no-daemon (daemon disabled; warm page cache; identical preparation both sides).
  • Recorded phases: clean-checkout baseline and same-command after (20 runs each, stable binary path), 8 paired AB/BA comparison hyperfine blocks (--warmup 3 --runs 8, order alternating, 64 samples per binary), and correctness validation, all via run_performance_command with binary and corpus fingerprints.

Results (recorded evidence)

End-to-end, cal.com dry run (8 balanced blocks, block speedup = 1 − candidate_median/baseline_median):

block order baseline median candidate median speedup
1 AB 151.9 ms 138.0 ms +9.19%
2 BA 145.3 ms 149.4 ms −2.85%
3 AB 148.1 ms 143.9 ms +2.83%
4 BA 145.7 ms 145.3 ms +0.31%
5 AB 157.3 ms 149.1 ms +5.20%
6 BA 151.4 ms 144.6 ms +4.53%
7 AB 153.4 ms 144.4 ms +5.90%
8 BA 163.3 ms 142.4 ms +12.85%
  • Mean block speedup +4.74% (median +4.87%); both orders improve (AB +5.78%, BA +3.71%); bootstrap (20k resamples) 95% CI of mean block speedup [+1.59%, +7.91%]; pooled medians 150.8 → 144.4 ms (−6.5 ms, −4.28%, n=64/64).
  • Recorded baseline vs after phases (same command text, 20 runs): 153.0 ± 8.9 ms → 142.0 ± 6.0 ms.
  • Earlier independent 12-block set against a bit-different (pre-rustfmt, semantically identical) candidate build agreed: mean +3.30%, both orders positive, 95% CI [+2.34%, +4.23%].

Mechanism corroboration (targeted benchmark; full parse + all_dependencies + resolve_package sweep over all 3,935 entries ×20 iterations per process; baseline binary built from a pristine worktree of 37be819, candidate from this diff; identical bench source, outputs identical keys=3935 deps=4247 resolved=4107): 6 balanced AB/BA hyperfine blocks, 60 samples per binary, mean block speedup +11.62%, both orders positive (AB +12.76%, BA +10.47%), bootstrap 95% CI [+9.27%, +13.92%], pooled medians 676.9 → 594.2 ms (−12.2%).

Non-regression sanity (recorded): payload (pnpm; berry path not executed) 90.2 ± 3.7 ms vs 88.1 ± 4.6 ms — unchanged within noise.

Correctness

  • cargo test -p turborepo-lockfiles: 314/314 pass, including a new exhaustive differential test (all 55,987 strings up to length 6 over {@, /, a, b, :, \n} compared against the original regexes, kept in-test as oracles) and realistic/edge cases (Unicode, patch locators, @a@b/c@1.0.0, trailing @, newline-in-range, empty string).
  • cargo clippy -p turborepo-lockfiles --all-targets and cargo fmt --check: clean.
  • End-to-end equality with both preserved binaries on cal.com: --dry=json output byte-equal modulo the random run id (115 tasks; all task hashes and global hash identical); turbo prune @calcom/web outputs recursively identical, pruned yarn.lock byte-identical.

Review

gpt_performance_reviewer (openai/gpt-5.6-sol) approved the exact final diff after one round of blocking findings (the initial mechanism benchmark lacked reproducible source, paired blocks, and CIs; it was replaced with the fully provenance-tracked paired benchmark above). Reviewer summary: parsers preserve the original regex semantics with exhaustive differential coverage and unchanged API/error behavior; targeted benchmark and end-to-end paired evidence are consistent with the regex-elimination mechanism; approval limited to the stated cal.com workload claims.

Limitations

  • The change only affects yarn-berry repositories; the measured claim is specific to the cal.com workload. Other berry repos are expected to benefit in proportion to lockfile size, but no cross-repository number is claimed.
  • Measurements were taken on a shared 2-vCPU VM with documented noise; mitigations: balanced AB/BA blocks, medians, bootstrap CIs, and an independent earlier block set that agrees.

@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
examples-basic-web Ready Ready Preview Aug 19, 2026 9:23pm
examples-designsystem-docs Ready Ready Preview Aug 19, 2026 9:23pm
examples-gatsby-web Ready Ready Preview Aug 19, 2026 9:23pm
examples-kitchensink-blog Ready Ready Preview Aug 19, 2026 9:23pm
examples-nonmonorepo Ready Ready Preview Aug 19, 2026 9:23pm
examples-svelte-web Ready Ready Preview Aug 19, 2026 9:23pm
examples-tailwind-web Ready Ready Preview Aug 19, 2026 9:23pm
examples-vite-web Ready Ready Preview Aug 19, 2026 9:23pm
turbo-site Ready Ready Preview Aug 19, 2026 9:23pm
turborepo-factory Ready Ready Preview Aug 19, 2026 9:23pm

@anthonyshew
anthonyshew marked this pull request as ready for review August 19, 2026 21:19
@anthonyshew
anthonyshew requested review from a team and tknickman August 19, 2026 21:19
@anthonyshew
anthonyshew enabled auto-merge (squash) August 19, 2026 21:21
@anthonyshew
anthonyshew merged commit 00e9f66 into main Aug 19, 2026
49 of 53 checks passed
@anthonyshew
anthonyshew deleted the agents/performance-2026-08-19 branch August 19, 2026 21:48
github-actions Bot added a commit that referenced this pull request Aug 25, 2026
## Release v2.10.12

> [!CAUTION]
> Versioned docs aliasing FAILED. [View
logs](https://github.com/vercel/turborepo/actions/runs/32882264217)

### Changes

- chore: Release Turborepo 2.10.11 (#13765) (`1fb1e86`)
- feat: Refresh documentation social cards (#13764) (`510777b`)
- fix: Preserve showcase logo sizes (#13766) (`b03ec9d`)
- fix: Refine mobile homepage interactions (#13767) (`a253dce`)
- fix: Align homepage KPIs to the right (#13769) (`373fbd3`)
- fix: Prevent homepage KPI overflow (#13770) (`fc02d72`)
- chore: Update Geistdocs to 1.20.4 (#13771) (`0689ad9`)
- perf: Skip Unused Workspace Config Stats (#13746) (`5503fde`)
- chore: Update with-solid example (#13752) (`43c555d`)
- chore: Update with-tailwind example (#13762) (`c436362`)
- perf: Stream dry-run JSON output (#13760) (`8138ce0`)
- chore: Update with-ultracite example (#13772) (`37be819`)
- perf: Merge same-prefix tree-wildcard globs into one directory walk
(#13763) (`59d4901`)
- chore: Update with-svelte example (#13118) (`bebcfc8`)
- chore: Add unified agent control plane (#13757) (`695a172`)
- fix: Remove incremental task caching (#13773) (`3d69e42`)
- chore: Rename agents app to factory (#13774) (`0a01c2d`)
- chore: Update oxlint and oxfmt (#13777) (`9088245`)
- feat: Add security.txt endpoint (#13778) (`5f9260b`)
- feat: Redesign factory control plane (#13775) (`ffd06d4`)
- perf: Replace regex captures with hand-written parsers in berry
lockfile identifiers (#13776) (`00e9f66`)
- chore: Upgrade the factory eve agent to 0.39.3 (#13783) (`c4fc5c8`)
- chore: Update with-rsbuild-module-federation example (#13786)
(`45b1257`)
- perf: Index Berry lockfile resolution overrides by dependency name
(#13787) (`e89eddd`)
- chore: Update remote cache action to v1.1.0 (#13789) (`56162b8`)
- docs: Fix reference links and validation (#13784) (`0423d70`)
- feat: Add SSH command affordance for factory sandboxes (#13779)
(`0cfccdd`)
- fix: Show invalid affected task glob (#13793) (`ef1ef92`)
- perf: Skip unused repository indexing for package listings (#13792)
(`acd5ae5`)
- feat: Rebuild the factory image on every merge to main (#13781)
(`1c165b3`)
- chore: Add full-page terminal SSH sessions to Factory sandbox
inventory (#13780) (`d640c2e`)
- chore: Update with-shell-commands example (#13791) (`476e382`)
- chore: Allow SSH terminal for completed-run sandboxes in Factory
(#13782) (`067dfba`)
- fix: Decouple graceful shutdown tests from the shell commands example
(#13799) (`72fac33`)
- feat: Start ad-hoc factory work from the operator page (#13798)
(`b9d13ca`)
- chore: Update with-solid example (#13797) (`d412981`)
- fix: Rebuild factory images without custom workflows (#13801)
(`0c54a80`)
- feat: Add factory navigation (#13802) (`092ee6d`)
- refactor: Migrate Factory styles to Tailwind (#13803) (`7fe373b`)
- feat: Add durable Factory workspaces (#13804) (`ccd79d3`)
- feat: Stream Factory sandbox as terminal (#13807) (`33d8b24`)
- fix: Restore Factory workspace creation (#13812) (`fd72cca`)
- fix: Update Factory session network policy (#13814) (`c579fec`)
- fix: Improve Factory terminal line spacing (#13815) (`a88e39b`)
- fix: Install Factory publishing skill (#13817) (`7b8cb14`)
- chore: Route Factory publishing through Eve (#13816) (`e05b81c`)
- feat: Standardize Factory meta titles to Turborepo suffix (#13819)
(`fd593b5`)
- perf: Skip Factory chat verification (#13820) (`39137a6`)
- fix: Restore Factory workspaces (#13823) (`0afd4b2`)
- docs: Fix inconsistent Yarn command in basic example (#13825)
(`3dd49d1`)
- chore: Update non-monorepo example (#13808) (`d2a673f`)
- perf: Batch package detail queries (#13809) (`331183e`)
- chore: Update basic example (#13824) (`f06836d`)
- fix: Include virtual tasks in affected query (#13805) (`89a9b78`)
- fix: Add workspace approval controls (#13827) (`02dfd21`)
- fix: Prevent chat SSH command overflow (#13828) (`d9eaff5`)
- fix: Update Factory pull request branches (#13831) (`b670754`)
- chore: Add operator chat model selector (#13833) (`bb2fcb3`)
- fix: Move model selector to workspace creation (#13835) (`72805d7`)
- chore: Skip redundant Factory PR approval (#13837) (`bbe5406`)
- chore: Use geistdocs 1.23.1 (#13834) (`3787c06`)
- chore: Handle feedback on Factory pull requests (#13836) (`a76330b`)
- fix: Escape ampersands in RSS feed enclosure URLs (#13839) (`7107f26`)
- chore: Add automatic issue handling (#13840) (`e1674e4`)
- chore: Alert Slack for low-confidence issues (#13841) (`f153cda`)
- feat: Require high confidence for issue fixes (#13842) (`c97782b`)
- fix: Run pnpm directly on Windows (#13843) (`9d2b03b`)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
anthonyshew pushed a commit that referenced this pull request Aug 27, 2026
## Release v2.10.13-canary.1

> [!CAUTION]
> Versioned docs aliasing FAILED. [View
logs](https://github.com/vercel/turborepo/actions/runs/33018929115)

### Changes

- chore: Release Turborepo 2.10.11-canary.4 (#13759) (`9f94a7d`)
- feat: Expand performance agent toolbox (#13761) (`f924510`)
- docs: Redesign Turborepo homepage (#13702) (`09bf969`)
- fix: Tolerate transient input files (#13734) (`3226457`)
- chore: Release Turborepo 2.10.11 (#13765) (`1fb1e86`)
- feat: Refresh documentation social cards (#13764) (`510777b`)
- fix: Preserve showcase logo sizes (#13766) (`b03ec9d`)
- fix: Refine mobile homepage interactions (#13767) (`a253dce`)
- fix: Align homepage KPIs to the right (#13769) (`373fbd3`)
- fix: Prevent homepage KPI overflow (#13770) (`fc02d72`)
- chore: Update Geistdocs to 1.20.4 (#13771) (`0689ad9`)
- perf: Skip Unused Workspace Config Stats (#13746) (`5503fde`)
- chore: Update with-solid example (#13752) (`43c555d`)
- chore: Update with-tailwind example (#13762) (`c436362`)
- perf: Stream dry-run JSON output (#13760) (`8138ce0`)
- chore: Update with-ultracite example (#13772) (`37be819`)
- perf: Merge same-prefix tree-wildcard globs into one directory walk
(#13763) (`59d4901`)
- chore: Update with-svelte example (#13118) (`bebcfc8`)
- chore: Add unified agent control plane (#13757) (`695a172`)
- fix: Remove incremental task caching (#13773) (`3d69e42`)
- chore: Rename agents app to factory (#13774) (`0a01c2d`)
- chore: Update oxlint and oxfmt (#13777) (`9088245`)
- feat: Add security.txt endpoint (#13778) (`5f9260b`)
- feat: Redesign factory control plane (#13775) (`ffd06d4`)
- perf: Replace regex captures with hand-written parsers in berry
lockfile identifiers (#13776) (`00e9f66`)
- chore: Upgrade the factory eve agent to 0.39.3 (#13783) (`c4fc5c8`)
- chore: Update with-rsbuild-module-federation example (#13786)
(`45b1257`)
- perf: Index Berry lockfile resolution overrides by dependency name
(#13787) (`e89eddd`)
- chore: Update remote cache action to v1.1.0 (#13789) (`56162b8`)
- docs: Fix reference links and validation (#13784) (`0423d70`)
- feat: Add SSH command affordance for factory sandboxes (#13779)
(`0cfccdd`)
- fix: Show invalid affected task glob (#13793) (`ef1ef92`)
- perf: Skip unused repository indexing for package listings (#13792)
(`acd5ae5`)
- feat: Rebuild the factory image on every merge to main (#13781)
(`1c165b3`)
- chore: Add full-page terminal SSH sessions to Factory sandbox
inventory (#13780) (`d640c2e`)
- chore: Update with-shell-commands example (#13791) (`476e382`)
- chore: Allow SSH terminal for completed-run sandboxes in Factory
(#13782) (`067dfba`)
- fix: Decouple graceful shutdown tests from the shell commands example
(#13799) (`72fac33`)
- feat: Start ad-hoc factory work from the operator page (#13798)
(`b9d13ca`)
- chore: Update with-solid example (#13797) (`d412981`)
- fix: Rebuild factory images without custom workflows (#13801)
(`0c54a80`)
- feat: Add factory navigation (#13802) (`092ee6d`)
- refactor: Migrate Factory styles to Tailwind (#13803) (`7fe373b`)
- feat: Add durable Factory workspaces (#13804) (`ccd79d3`)
- feat: Stream Factory sandbox as terminal (#13807) (`33d8b24`)
- fix: Restore Factory workspace creation (#13812) (`fd72cca`)
- fix: Update Factory session network policy (#13814) (`c579fec`)
- fix: Improve Factory terminal line spacing (#13815) (`a88e39b`)
- fix: Install Factory publishing skill (#13817) (`7b8cb14`)
- chore: Route Factory publishing through Eve (#13816) (`e05b81c`)
- feat: Standardize Factory meta titles to Turborepo suffix (#13819)
(`fd593b5`)
- perf: Skip Factory chat verification (#13820) (`39137a6`)
- fix: Restore Factory workspaces (#13823) (`0afd4b2`)
- docs: Fix inconsistent Yarn command in basic example (#13825)
(`3dd49d1`)
- chore: Update non-monorepo example (#13808) (`d2a673f`)
- perf: Batch package detail queries (#13809) (`331183e`)
- chore: Update basic example (#13824) (`f06836d`)
- fix: Include virtual tasks in affected query (#13805) (`89a9b78`)
- fix: Add workspace approval controls (#13827) (`02dfd21`)
- fix: Prevent chat SSH command overflow (#13828) (`d9eaff5`)
- fix: Update Factory pull request branches (#13831) (`b670754`)
- chore: Add operator chat model selector (#13833) (`bb2fcb3`)
- fix: Move model selector to workspace creation (#13835) (`72805d7`)
- chore: Skip redundant Factory PR approval (#13837) (`bbe5406`)
- chore: Use geistdocs 1.23.1 (#13834) (`3787c06`)
- chore: Handle feedback on Factory pull requests (#13836) (`a76330b`)
- fix: Escape ampersands in RSS feed enclosure URLs (#13839) (`7107f26`)
- chore: Add automatic issue handling (#13840) (`e1674e4`)
- chore: Alert Slack for low-confidence issues (#13841) (`f153cda`)
- feat: Require high confidence for issue fixes (#13842) (`c97782b`)
- fix: Run pnpm directly on Windows (#13843) (`9d2b03b`)
- chore: Release Turborepo 2.10.12 (#13844) (`32748f5`)
- fix: Remove unsupported remote cache environment variable (#13845)
(`b4c2eed`)
- fix: Copy TUI selections locally over SSH (#13847) (`03df632`)
- feat: Use uv workspace metadata (#13848) (`fa1ca7d`)
- feat: Support Python virtual environments (#13849) (`7f66dbd`)
- fix: Scope uv lockfile affectedness (#13850) (`1e074f3`)
- test: Isolate uv prune configuration (#13851) (`9f2fd33`)
- fix: Explain disabled uv task caching (#13852) (`0f59d11`)
- fix: Explain uv identity probe failures (#13853) (`eabe73a`)
- fix: Explain uncached Cargo library builds (#13855) (`35ce2fa`)
- fix: Explain disabled Cargo task caching (#13854) (`39821f6`)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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