[Performance] Optimize linesToColumns in string utilities#7551
[Performance] Optimize linesToColumns in string utilities#7551gonzaloriestra wants to merge 1 commit into
Conversation
Refactor `linesToColumns` to use a single-pass width calculation and cache unstyled lengths. This reduces calls to the expensive `unstyled` utility (which uses regex) by 50% and eliminates redundant array iterations and intermediate array creations.
|
👋 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. |
WHY are these changes introduced?
The
linesToColumnsutility function inpackages/cli-kitis used to format CLI output into aligned columns. The previous implementation was inefficient because it:unstyled(row).lengthtwice for every cell (once for width calculation and once for padding). Sinceunstyleduses regex to strip ANSI escape codes, this is relatively expensive.WHAT is this pull request doing?
This PR optimizes
linesToColumnsby:unstyledutility by 50%.How to test your changes?
Run the following command to verify that the string utility tests still pass:
pnpm --filter @shopify/cli-kit vitest run src/public/common/string.test.tsDuplicate check
Query:
gh pr list --repo Shopify/cli --state all --limit 200 --search 'label:"Jules" "Performance" in:title' --json number,title,state,url,body,filesFallback:
git log --grep="\[Performance\]" --onelineClosest prior PRs:
9d50d23b6 [Performance] Optimize crypto utility functions: Optimized crypto helpers but didn't touch string utilities.024fbcaf5 [Performance] Optimize Liquid template rendering: Optimized template rendering logic.a1c7666c9 [Performance] Optimize CLI startup and project discovery: Optimized project discovery and file system loading.This PR is meaningfully different because it targets core string formatting logic in
packages/cli-kit/src/public/common/string.ts, which was not addressed in previous performance PRs.Checklist
pnpm changeset add(Note: internal optimization, skipped changeset as per standard performance task scope)PR created automatically by Jules for task 6574077092894988872 started by @gonzaloriestra