Reduce Maven version component allocations - #49
Merged
Merged
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Address the two moderate version.go allocation and reference-retention issues before approval.
Pull request overview
Reduces allocations in Maven version parsing and normalization while preserving comparison behavior.
Changes:
- Preallocates component capacity from token counts.
- Compacts pre-qualifier zeros in place.
- Adds Maven correctness tests and allocation benchmarks.
File summaries
| File | Summary |
|---|---|
version.go |
Optimizes Maven parsing and normalization; unresolved issues remain around skipped components and stale truncated references. |
maven_allocation_test.go |
Adds Maven regression tests and allocation benchmarks. |
Review details
Suppressed comments (2)
version.go:660
len(parts)is not a lower bound on emitted components: empty segments and aliases such asga,final, andreleaseare skipped. Thus valid inputs likefinalnow allocate a component backing array that the old code left nil, and a long qualifier-only input allocates O(tokens) unused capacity. Initialize the result lazily on the first non-skipped component (or otherwise size it from emitted components) so this optimization does not regress those inputs.
result = make([]mavenComponent, 0, len(parts))
version.go:724
- The in-place compaction leaves the removed components in the backing array beyond the returned length. Those stale components still reference the strings produced for the trimmed numeric tokens, so long zero runs remain live for as long as the normalized slice does; the previous exact-size rebuild released those references. Clear the truncated tail after the append (or copy into an exact-size slice) to avoid this retention regression.
components = append(components[:baseEnd], components[firstSublistIdx:]...)
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 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.
Reserve Maven version component capacity from the token count and remove zeros before qualifiers in place, avoiding repeated slice growth and a replacement allocation during normalization. Comparison rules remain unchanged.
Public comparison benchmarks use 44–55% fewer allocated bytes and 25–32% fewer allocations.
HighestSatisfyingover 500 Maven versions uses 59% fewer bytes and 32% fewer allocations.