perf(templates): rm double parsing in template loading#6796
Merged
dwisiswant0 merged 1 commit intodevfrom Feb 4, 2026
Merged
Conversation
Refactor `ParseTemplateFromReader` to parse YAML once after applying preprocessors, avoiding redundant parsing for verification. Also add `parseTemplateNoVerify` and `applyTemplateVerification` helpers to separate parsing from signature verification logic to reduce CPU overhead during startup template loading. Signed-off-by: Dwi Siswanto <git@dw1.io>
Contributor
WalkthroughRefactored template parsing flow in Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
dogancanbakir
approved these changes
Feb 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
perf(templates): rm double parsing in template loading
Refactor
ParseTemplateFromReaderto parse YAMLonce after applying preprocessors, avoiding
redundant parsing for verification. Also add
parseTemplateNoVerifyandapplyTemplateVerificationhelpers to separateparsing from signature verification logic to
reduce CPU overhead during startup template
loading.
Proof
Key memory improvements:
YAML parsing:
yaml.(*parser).node: -15.41MB (-2.24%)yaml.(*parser).scalar: -2.15MByaml.(*parser).mapping: -0.77MB (cum -19.39MB)yaml.(*parser).sequence: -0.39MB (cum -19.23MB)Reflection ops:
reflect.New: -1.51MBreflect.MakeSlice: -113.55KBreflect.MakeMap: -60.35KBreflect.growslice: -296.05KBreflect.SetMapIndex: -66.27KBTemplate processing:
parseTemplate: -8MB flat (cum -25.45MB)ParseTemplateFromReader: -17.91MB cumrandStrPreprocessor): -35.81KB (cum -1.32MB)bytes.Replace: -1.27MB (less template data manipulation)Mixed result:
parseTemplateNoVerify: +8.09MB flat but still achieves overall reductions through downstream savingsgo tool pprofThe patch successfully reduces memory allocations by eliminating redundant YAML parsing and reducing reflection overhead during template loading, which shows clear benefits in the YAML parser allocs.
Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.