Repository navigation
Conversation
`addOrModify` walks to the file's parent directory, then hands the file to `bulkAddOrModify`, which walks to the same directory again. This is paid on every watched file change. This adds the file to the directory node from the first walk instead, which makes `addOrModify` about 45% faster. It also fixes the file's path when its parent is a symlink to the project root. The parent's canonical path is then `''`, and joining it to the basename gave an absolute path (`/new.js`), so the file was added outside the project, at `../../new.js` from a project at `/project/root`. @kitten spotted this in expo/expo#52449 (comment). ## Benchmark AI-driven. Paired against `main`, 16 interleaved rounds, with a byte-identical copy of `main` as a noise control. | | `main` | This PR [95% CI] | Control [95% CI] | |---|---|---|---| | `addOrModify`, existing file | 1207 ns | -47.1% [-48.0, -46.4] | -0.3% [-1.2, +1.4] | | `addOrModify`, new file | 1323 ns | -44.5% [-44.8, -43.7] | +0.6% [-0.2, +1.3] | | `remove` | 710 ns | -0.9% [-2.3, -0.5] | +0.9% [-0.3, +1.8] | | Cold build | 137 ms | +0.5% [-1.0, +1.2] | +0.1% [-1.1, +0.6] | | Warm start | 133 ms | +0.6% [-1.1, +2.2] | +1.0% [-2.2, +3.1] | `bulkAddOrModify` is unchanged (0.455 ms on `main`, 0.456 ms with this PR, 200 calls in a fresh process each). ## Changelog ``` - **[Fix]**: Fix the path of a file added through a symlink to the project root ``` ## Test plan New unit test, failing on `main`. Same benchmark app and method as #2204. Fuzzed against `main` on 20,000 random symlinked trees, comparing results, errors and change events. 16 trees differ, each adding through a symlink to the project root, where `main` adds the file outside the project.
Metro review: Looks goodRisk: medium · Commit:
No findings. Verified
Benchmarks (base vs this PR)
Method
Not run: I didn't rerun the PR's cold-build, warm-start and Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
|
I think tbh, this isn't a sufficiently hot path to justify the duplication - it's only used on file changes so typically on a small batch. It was motivated by this being one of the last areas where Thanks @vzaidman for the nudge :) |
addOrModifywalks to the file's parent directory, then hands the file tobulkAddOrModify, which walks to the same directory again. This is paid on every watched file change. This adds the file to the directory node from the first walk instead, which makesaddOrModifyabout 45% faster.It also fixes the file's path when its parent is a symlink to the project root. The parent's canonical path is then
'', and joining it to the basename gave an absolute path (/new.js), so the file was added outside the project, at../../new.jsfrom a project at/project/root. @kitten spotted this in expo/expo#52449 (comment).Benchmark
AI-driven. Paired against
main, 16 interleaved rounds, with a byte-identical copy ofmainas a noise control.mainaddOrModify, existing fileaddOrModify, new fileremovebulkAddOrModifyis unchanged (0.455 ms onmain, 0.456 ms with this PR, 200 calls in a fresh process each).Changelog
Test plan
New unit test, failing on
main. Same benchmark app and method as #2204.Fuzzed against
mainon 20,000 random symlinked trees, comparing results, errors and change events. 16 trees differ, each adding through a symlink to the project root, wheremainadds the file outside the project.