Skip to content

Reduce Maven version component allocations - #49

Merged
andrew merged 1 commit into
mainfrom
perf/maven-component-allocation
Sep 14, 2026
Merged

andrew merged 1 commit into
mainfrom
perf/maven-component-allocation

Conversation

@andrew

@andrew andrew commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

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. HighestSatisfying over 500 Maven versions uses 59% fewer bytes and 32% fewer allocations.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 as ga, final, and release are skipped. Thus valid inputs like final now 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.

@andrew
andrew merged commit f0d90be into main Sep 14, 2026
6 checks passed
@andrew
andrew deleted the perf/maven-component-allocation branch September 14, 2026 02:20
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.

2 participants