Skip to content

perf(theme): single-pass string literals in stripJsonc - #1400

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1360-jsonc-single-pass-strings
Oct 10, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1360-jsonc-single-pass-strings

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Closes #1360

Problem

For every " stripJsonc ran _copyStringLiteral (char by char into a new StringBuffer) and then _skipStringLiteral over the same characters again: two scans and one buffer + string per literal, thousands of times for a VS Code theme.

Change

One helper, _stringLiteralEnd, finds the end of the literal in a single pass (on code units, no per-character strings); stripJsonc writes input.substring(start, end). Same end offsets as the old skip (unterminated literal goes to the end of input, a backslash escapes the next character), so the output is byte for byte the same.

Tests

Added to jsonc_preprocessor_test.dart: escapes preserved, comment markers and ,] / ,} inside strings survive, unterminated string, trailing backslash, and a 200-token document with comments and trailing commas. The existing tests are unchanged.

Not run locally; CI is the check.

stripJsonc scanned every string literal twice (copy, then skip) and built
a StringBuffer per literal. A single scan now finds the closing quote and
the literal is written as a substring. Closes #1360.
@github-actions github-actions Bot added theme Theming, colors, VS Code themes performance Theme parser epic label: performance core Core library logic and services P3 Low priority / Polish & Enhancements labels Oct 10, 2026
@github-actions github-actions Bot added this to the Theme system milestone Oct 10, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit edae090 into dev Oct 10, 2026
13 checks passed
@ZhuchkaTriplesix
ZhuchkaTriplesix deleted the issue/1360-jsonc-single-pass-strings branch October 11, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core library logic and services P3 Low priority / Polish & Enhancements performance Theme parser epic label: performance theme Theming, colors, VS Code themes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant