turbo
c5b05d0e - perf: Match node_modules-style exclusions by path segment instead of compiling globs (#14634)

Commit
49 days ago
perf: Match node_modules-style exclusions by path segment instead of compiling globs (#14634) Stacked on #14510 (`shew/perf-plain-exclusions`); please review that first. This PR's diff and numbers are relative to that branch. Every command that discovers packages compiled the package manager's default workspace exclusions into wax regexes: `**/node_modules/**` and `**/bower_components/**` for pnpm, and `**/node_modules/**` for npm and several other package managers. User `!**/<name>` workspace patterns were compiled the same way. On small repositories that compile is a visible share of the command: workspace discovery in create-t3-turbo took about 1.9 ms, most of it building those regexes and matching every walked entry against them. This change extends #14510's plain exclusions to `<prefix>/**/<segment>` and `<prefix>/**/<segment>/**`, and matches them by path component instead of compiling a regex. ```diff compile_globs for each exclusion `<prefix>/**`, literal -> path prefix / equality (#14510) + `<prefix>/**/<segment>[/**]` -> path component check anything else -> wax::Glob::new retain index hashes that are not excluded + `[<prefix>/]**/<segment>[/**]` -> path component check anything else -> wax ``` The matcher reproduces wax's encoding exactly: the inner globstar is `(?:/|/(.*/))`, a leading one is `(?:/?|(.*/))`, and a trailing one is `(?:/?|/(.*))`, all without the `s` flag. That means: - The segment must be a whole path component, so `my_node_modules` and `node_modules_extra` are not excluded. For the bare `**/<segment>` form it must be the last component. - Matching is case-sensitive, like wax off Windows, so `Node_Modules` is not excluded. - A path whose remainder below the prefix contains a newline never matches, because wax's `.*` doesn't match newlines. - Pruning a directory on the bare form stays exact, because exclusions are always expanded with their `/**` twin, as for literals in #14510. - On Windows, where wax matches literals case-insensitively by default, these exclusions keep going through wax. ## Measurements `release-turborepo` builds of #14510 (the base of this stack) and this branch, on Linux x86_64 with 8 vCPU and 16 GB. Each comparison uses `hyperfine -N` in 8 blocks of 30 runs per binary, alternating both command order and which slot directory each binary runs from. Both binaries were freshly copied and the page cache was dropped before every block, with 5 warmups per block. The table reports the per-block median speedup with a bootstrap 95% CI. Workloads are `t3-oss/create-t3-turbo@8f945b7b` and `dubinc/dub@1f30d590`; dub had `pipeline` renamed to `tasks` in its `turbo.json` so 2.x runs it. Each was measured on two hosts. | Workload | Host / THP | #14510 median | Branch median | Speedup | 95% CI | |---|---|---|---|---|---| | create-t3-turbo `turbo ls` | 1 / on | 13.6 ms | 12.5 ms | +8.5% | +5.1% to +11.9% | | create-t3-turbo `turbo ls` | 1 / off | 9.6 ms | 8.6 ms | +8.3% | +4.9% to +11.9% | | create-t3-turbo `turbo ls` | 2 / on | 12.0 ms | 11.3 ms | +5.8% | +3.5% to +7.9% | | create-t3-turbo `turbo ls` | 2 / off | 9.0 ms | 8.4 ms | +7.7% | +3.8% to +11.5% | | dub `turbo ls` | 1 / on | 12.7 ms | 11.7 ms | +7.7% | +4.4% to +10.9% | | dub `turbo ls` | 1 / off | 9.7 ms | 9.1 ms | +6.0% | +1.5% to +11.5% | | dub `turbo ls` | 2 / on | 11.8 ms | 10.9 ms | +5.2% | +1.6% to +8.5% | | dub `turbo ls` | 2 / off | 8.4 ms | 8.0 ms | +3.1% | −2.5% to +6.8% | | create-t3-turbo `run build --dry=json` | 1 / 2 | 33.7 / 31.4 ms | 33.3 / 31.2 ms | +1.3% / +0.5% | −1.2% to +3.6% / −1.3% to +2.7% | | dub `run build --dry=json` | 1 / 2 | 59.9 / 55.1 ms | 57.8 / 54.8 ms | +2.4% / +1.0% | −0.6% to +5.1% / −1.6% to +4.0% | | `turbo --version` | 1 / 2 | 5.4 / 4.7 ms | 5.6 / 4.8 ms | −0.5% / −0.4% | −7.4% to +5.9% / −3.3% to +3.4% | The branch takes 1.5 to 1.8 fewer transparent-huge-page faults per `ls` run, since it builds no regexes, so `ls` is also reported with THP disabled. The create-t3-turbo `ls` result clears a layout-control build (#14510 plus a no-op `black_box` on a cold path) on both hosts. The dub `ls` result clears it on the second host but not the first, where the control itself measured +4.6% (THP on) and +3.7% (THP off). Dry runs show no measurable change, and `--version` is unchanged. Mechanism, from the median of 9 profiled runs of each binary: workspace discovery drops from 1.92 ms to 0.74 ms in create-t3-turbo, and from 3.15 ms to 0.93 ms in dub. `compile_globs` drops from 0.81 ms to 0.18 ms and from 1.54 ms to 0.41 ms respectively. ## Manual verification - Compared `turbo ls`, `turbo ls --output=json`, and `turbo run build` / `turbo run lint` with `--dry=json` between `main`, #14510, and this branch on `t3-oss/create-t3-turbo@8f945b7b`, `dubinc/dub@1f30d590`, `triggerdotdev/trigger.dev@442702e8`, `payloadcms/payload@24ac8955`, `calcom/cal.com@176037d0`, `onejs/one@9483d947`, and `vercel/turborepo`. Package lists and every task and input hash are identical. Tasks that don't exist in a repository fail the same way on every binary. - Ran the same comparison on two fixtures built from create-t3-turbo. They add packages under `my_node_modules`, `node_modules_extra`, `Node_Modules`, `bower_components`, and `packages/node_modules`. They also add nested `node_modules` and `test` directories under a `packages/**` workspace glob, a symlink named `node_modules`, a symlinked package directory with its own `node_modules`, and directories with newlines in their names. Discovered packages and all outputs are identical across the three binaries.
Author
Parents
Loading