refactor(skills): single-pass escapeXML, drop no-op Sprintf#3245
Open
corporatepiyush wants to merge 1 commit into
Open
refactor(skills): single-pass escapeXML, drop no-op Sprintf#3245corporatepiyush wants to merge 1 commit into
corporatepiyush wants to merge 1 commit into
Conversation
escapeXML made three sequential strings.ReplaceAll passes (three
allocations). Replace it with a package-level strings.NewReplacer that
does a single pass, built once. Behaviour is byte-identical: it still
escapes only & < > (not " '), and single-pass replacement does not
re-escape the & introduced by the < / > replacements. Pinned by the new
TestEscapeXMLGolden.
Also drop fmt.Sprintf(" <skill>") in BuildSkillsSummary: with no format
directives it is just the literal string.
Benchmark escapeXML (go1.26, darwin/arm64, -benchmem):
1.64µs -> 0.90µs 2944 -> 2048 B/op 3 -> 2 allocs (1.8x faster, 30% less mem)
|
|
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.
📝 Description
Two tiny cleanups in
pkg/skills/loader.go:escapeXMLmade three sequentialstrings.ReplaceAllpasses (three allocations). Replaced with a package-levelstrings.NewReplacer(single pass, built once). Byte-identical: it still escapes only&,<,>(not"/'), and single-pass replacement does not re-escape the&introduced by the</>replacements. Pinned by the newTestEscapeXMLGolden.fmt.Sprintf(" <skill>")inBuildSkillsSummaryhas no format directives → replaced with the plain string literal" <skill>".🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
N/A — self-contained cleanup.
📚 Technical Context
strings.NewReplacerbuilds its matcher once and replaces in a single pass; the old chain walked the string three times with three intermediate allocations.escapeXMLruns for every skill name/description/path in the skills summary that is injected into the system prompt.Benchmark (go1.26, darwin/arm64,
-benchmem):escapeXML🧪 Test Environment
Verification:
go vet+go test ./pkg/skills/pass (incl. newTestEscapeXMLGolden);gofmtclean.☑️ Checklist