Reduce allocations in MakePURLString - #26
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes PURL string construction by routing MakePURLString/BuildPURLString through a direct encoder path and pre-sizing the output buffer based on escaped component lengths, reducing intermediate allocations while preserving canonical escaping behavior across ecosystems.
Changes:
- Introduces a shared
buildPURLStringfast-path encoder with capacity pre-sizing based on escaped lengths. - Refactors ecosystem string handling toward shared constants and updates
MakePURLStringto use the direct encoder. - Adds expanded
MakePURLStringcompatibility tests and new benchmarks covering package/version PURL construction for npm (including scoped), and Go.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| makepurl.go | Adds direct PURL string builder + escaped-length estimators and updates namespace encoding loop. |
| ecosystem.go | Centralizes ecosystem constants and routes MakePURLString through the new builder. |
| ecosystem_test.go | Expands MakePURLString tests to cover escaping and ecosystem-specific behavior with canonical cross-checks. |
| ecosystem_bench_test.go | Adds benchmarks for MakePURLString across representative ecosystems/packages. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Route
MakePURLStringthrough the direct package URL encoder and pre-size output buffers using escaped lengths. This avoids intermediatePURLallocations while preserving canonical component escaping across ecosystems.Add benchmarks covering package and version PURL construction for npm, scoped npm, and Go, plus compatibility cases for ecosystem-specific splitting and escaping.