Skip to content

[Performance] Optimize linesToColumns in string utilities#7551

Draft
gonzaloriestra wants to merge 1 commit into
mainfrom
optimize-linestocolumns-performance-6574077092894988872
Draft

[Performance] Optimize linesToColumns in string utilities#7551
gonzaloriestra wants to merge 1 commit into
mainfrom
optimize-linestocolumns-performance-6574077092894988872

Conversation

@gonzaloriestra
Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

The linesToColumns utility function in packages/cli-kit is used to format CLI output into aligned columns. The previous implementation was inefficient because it:

  1. Called unstyled(row).length twice for every cell (once for width calculation and once for padding). Since unstyled uses regex to strip ANSI escape codes, this is relatively expensive.
  2. Performed multiple redundant O(Cols * Rows) array mappings to calculate max widths and row lengths.

WHAT is this pull request doing?

This PR optimizes linesToColumns by:

  • Refactoring the column width calculation to use a single pass over the data.
  • Caching unstyled lengths in an intermediate structure, reducing calls to the expensive unstyled utility by 50%.
  • Eliminating redundant array mappings and intermediate array creations.

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.ts

Duplicate check

Query: gh pr list --repo Shopify/cli --state all --limit 200 --search 'label:"Jules" "Performance" in:title' --json number,title,state,url,body,files
Fallback: git log --grep="\[Performance\]" --oneline

Closest prior PRs:

  1. 9d50d23b6 [Performance] Optimize crypto utility functions: Optimized crypto helpers but didn't touch string utilities.
  2. 024fbcaf5 [Performance] Optimize Liquid template rendering: Optimized template rendering logic.
  3. 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

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch) and added a changeset with 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

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.
@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant