[Performance] Optimize directory copying by using relative paths in glob#7446
[Performance] Optimize directory copying by using relative paths in glob#7446gonzaloriestra wants to merge 1 commit intomainfrom
Conversation
By using the `cwd` option in `glob`, we get relative paths directly. This avoids the overhead of retrieving absolute paths and then performing manual string replacement for path normalization on every item in the directory. This is measurably faster for directories with many files. Also ensured `fast-glob` is dynamically imported/required within the functions to maintain CLI startup performance. Verified with unit tests and nx quality checks.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Description
Optimized
copyDirectoryContentsinpackages/cli-kit/src/public/node/fs.tsby using thecwdoption in theglobcall. This allows us to get relative paths directly fromfast-glob, avoiding expensive absolute path globbing and subsequent manual string manipulation (regex and replacement) for each file.How to test your changes?
Run the unit tests for
cli-kit:pnpm --filter @shopify/cli-kit vitest run src/public/node/fs.test.tsAll 34 tests (including 1 skipped on Linux) should pass.
Performance Impact
Reduces string manipulation overhead and avoids absolute path resolution in
fast-globwhen copying directories. This is particularly beneficial for large directories with many small files, which is a common scenario in CLI operations (e.g., app initialization or theme syncing).Checklist
pnpm lint,pnpm type-check, andpnpm test:unit.PR created automatically by Jules for task 13363153947624010045 started by @gonzaloriestra