Skip to content

perf(gotemplate-helm): skip the quote-normalize regex on quoteless lines#509

Open
alexmond wants to merge 1 commit into
mainfrom
perf/toyaml-quote-fastpath
Open

perf(gotemplate-helm): skip the quote-normalize regex on quoteless lines#509
alexmond wants to merge 1 commit into
mainfrom
perf/toyaml-quote-fastpath

Conversation

@alexmond

Copy link
Copy Markdown
Owner

Profiling a gitlab render loop (JFR → jvmlens) surfaced ConversionFunctions.removeUnnecessaryQuotes as 6% CPU and 1.2 GB allocation — it ran the QUOTED_VALUE regex + a Matcher on every line of every toYaml/toJson output. But QUOTED_VALUE requires a double-quoted scalar, and the large majority of rendered-manifest lines are unquoted.

Fix

An indexOf('"') < 0 fast-path appends quoteless lines verbatim and skips the regex entirely (+ size the StringBuilder to the input). Behaviour-identical — a quoteless line takes the old no-match branch.

Measured (jvmlens diff, 120× gitlab render)

  • removeUnnecessaryQuotesGONE from both hot paths (was 6% CPU) and allocation sites (was 1.2 GB)
  • Total allocation 23.4 GB → 22.2 GB (−1.1 GB, −5%) — real absolute reduction
  • (The Lexer/toYaml share rises in the diff are share-inversion from the smaller total; their absolute alloc fell or held.)

Correctness

88 jhelm-gotemplate-helm tests green (ConversionFunctionsTest covers toYaml byte-output, HelmConformanceTest); 346-chart byte-parity running as a safety net.

Profiling also surfaced an engine-side allocator (gotmpl4j CharUtils.isAnyOf doing an IntStream per call in the lexer, ~2 GB) — filed as alexmond/gotmpl4j#64.

🤖 Generated with Claude Code

Profiling a gitlab render loop (jvmlens over a JFR) showed
ConversionFunctions.removeUnnecessaryQuotes at 6% CPU and 1.2 GB allocation —
it ran the QUOTED_VALUE regex (plus a Matcher) on every line of every toYaml /
toJson output. QUOTED_VALUE requires a double-quoted scalar, so a line with no
'"' can never match; the large majority of rendered-manifest lines are unquoted.

Add an `indexOf('"') < 0` fast path that appends such lines verbatim and skips
the regex entirely. Behaviour-identical (a quoteless line takes the old
no-match branch). Also size the StringBuilder to the input length.

Measured (jvmlens diff, 120x gitlab render): removeUnnecessaryQuotes GONE from
both hot paths (was 6% CPU) and allocation sites (was 1.2 GB); total allocation
23.4 GB -> 22.2 GB (-1.1 GB, -5%). Verified byte-identical: 88
jhelm-gotemplate-helm tests green (ConversionFunctionsTest, HelmConformanceTest).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5yvjG89AqMHPAGJawSmg9
@github-actions

Copy link
Copy Markdown
Contributor
Overall Project 81.25% 🍏

There is no coverage information present for the Files changed

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

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