Skip to content

fix(preprocess): optimize file patching and fix edge-case bugs - #4021

Open
nghiphaam wants to merge 2 commits into
spicetify:mainfrom
nghiphaam:fix/preprocess-perf
Open

nghiphaam wants to merge 2 commits into
spicetify:mainfrom
nghiphaam:fix/preprocess-perf

Conversation

@nghiphaam

@nghiphaam nghiphaam commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Speeds up spicetify apply and cleans up a few issues in preprocess and utils:

  • Cache compiled regexes and move static []Patch slices to package level.
  • Use Find*SubmatchIndex in Replace* / FindFirstMatch / FindLastMatch to avoid matching twice and stop after the first match in ReplaceOnce.
  • Use strings.NewReplacer for cssTranslationMap on CSS files (same as JS) and combine literal hex color patches.
  • Parallelize file patching in Start and StartCSS using filepath.WalkDir.
  • Fix potential nil dereference in StartCSS, duplicate Spicetify.URI patch, missing bounds check in SeekToCloseParen, and defer inside loops in Unzip/Copy.
  • Skip writing unchanged files in ModifyFile.

Note: also removed --spice-card-elevated from colorPatches since it used the exact same #(242424|1f1f1f)\b regex as --spice-main-elevated above it and was unreachable.

Summary by CodeRabbit

  • Performance
    • Preprocessing and CSS color conversion now run concurrently, which can speed up builds.
  • Bug Fixes
    • CSS replacements are applied consistently, and XPUI stylesheets retain the legacy fixed-width grid rule.
    • Improved handling of logging and vendor integrations when processing supported application files.
    • File and archive operations now handle unchanged content and extraction errors more reliably.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository: spicetify/cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c1613a8f-41ef-471f-9983-e4c969a063d6
📥 Commits

Reviewing files that changed from the base of the PR and between a60d020 and 2227d71.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: spicetify/cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb2d8dce-b3b7-47cf-ae5b-c50f06291949
📥 Commits

Reviewing files that changed from the base of the PR and between 1684023 and a60d020.

📒 Files selected for processing: 2
  • src/preprocess/preprocess.go
  • src/utils/utils.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The changes update utility regex and file operations, and revise preprocessing to discover and process files concurrently. Preprocessing also uses precomputed CSS replacements and shared patch definitions, with checks for context-menu and vendor URI matches.

Changes: Preprocessing and Utilities

Layer / File(s) Summary
Regex matching and scanning helpers
src/utils/utils.go
Compiled regexes are cached. Replacement and matching helpers use match indices, and parenthesis scanning is bounded by the content length.
Archive and file operations
src/utils/utils.go
Archive entries are opened during extraction and closed after copying. Copy delegates to CopyFile. ModifyFile reports errors through PrintError, skips unchanged writes, and writes changed content with mode 0644.
Concurrent file preprocessing
src/preprocess/preprocess.go
Start and StartCSS discover files with WalkDir and process them concurrently with CPU-count limits. CSS-map replacers are precomputed, and color conversion patches are shared.
Preprocessing patch rules and safeguards
src/preprocess/preprocess.go
Logging, RTL, GraphQL, XPUI, and vendor patch definitions move to package scope. Context-menu discovery checks for a useRef match, and vendor URI export insertion checks for a URI body.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Start
  participant WalkDir
  participant Workers as Worker goroutines
  participant Progress as Progress bar
  Start->>WalkDir: Discover files
  WalkDir-->>Start: Return file entries
  Start->>Workers: Dispatch file processing
  Workers->>Progress: Increment progress under lock
Loading

Suggested reviewers: rxri

Merge Risk: ⚪ Minimal · up to a60d0

The inspected preprocessing changes preserve the relevant replacement behavior. No actionable issue remains from this review; the PR is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately summarizes the pull request. It identifies both the file-patching optimizations and the edge-case fixes described in the changes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nghiphaam
nghiphaam marked this pull request as ready for review October 14, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant