Skip to content

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

Merged
alexmond merged 1 commit into
mainfrom
perf/toyaml-quote-fastpath
Jun 29, 2026
Merged

perf(gotemplate-helm): skip the quote-normalize regex on quoteless lines#509
alexmond merged 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!

@alexmond alexmond merged commit 5bd353d into main Jun 29, 2026
2 checks passed
@alexmond alexmond deleted the perf/toyaml-quote-fastpath branch June 29, 2026 16:29
@github-actions

Copy link
Copy Markdown
Contributor
Overall Project 82.23% 🍏

There is no coverage information present for the Files changed

alexmond added a commit that referenced this pull request Jun 29, 2026
Adds docs/performance.adoc documenting jhelm's profile-driven performance
work, modelled on the gotmpl4j performance page but adapted to jhelm's
layer (chart rendering, not engine-vs-engine throughput).

Covers: the jhelm-vs-gotmpl4j layer split (and a link to gotmpl4j's own
perf page), the 540-chart parity corpus as the render benchmark, the
jvmlens live-attach methodology (incl. the surefire dumponexit gotcha and
scoping to org.alexmond.jhelm), where render time actually goes (parse/lex
vs inherent chart crypto vs jhelm orchestration), how to read share-
inversion in a profile diff, and an optimization-history table with the
measured jvmlens deltas for #573 (double-parse elimination) and #509
(toYaml quote-normalize fast-path). Linked into the nav after Core Engine.


Claude-Session: https://claude.ai/code/session_01U5yvjG89AqMHPAGJawSmg9

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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