Skip to content

perf: reduce allocations in NewV3 and NewV5#221

Merged
cameracker merged 2 commits into
gofrs:masterfrom
anatoly-kussul:perf-v3-v5-allocations
Sep 25, 2025
Merged

perf: reduce allocations in NewV3 and NewV5#221
cameracker merged 2 commits into
gofrs:masterfrom
anatoly-kussul:perf-v3-v5-allocations

Conversation

@anatoly-kussul

Copy link
Copy Markdown
Contributor
goos: linux
goarch: amd64
pkg: github.com/gofrs/uuid/v5
cpu: 12th Gen Intel(R) Core(TM) i5-12400F
                   │     old     │                 new                 │
                   │   sec/op    │   sec/op     vs base                │
Generator/NewV3-12   169.5n ± 1%   102.5n ± 1%  -39.55% (p=0.000 n=10)
Generator/NewV5-12   183.2n ± 2%   113.6n ± 1%  -37.96% (p=0.000 n=10)

                   │    old     │                  new                  │
                   │    B/op    │   B/op    vs base                     │
Generator/NewV3-12   144.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=10)
Generator/NewV5-12   168.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=10)

                   │    old     │                   new                   │
                   │ allocs/op  │ allocs/op   vs base                     │
Generator/NewV3-12   4.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)
Generator/NewV5-12   4.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)

@cameracker
cameracker requested a review from Copilot September 25, 2025 01:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the allocation performance of UUID generation methods NewV3 and NewV5 by eliminating all heap allocations. The changes inline the hash computation logic and use a pre-allocated buffer to avoid unnecessary memory allocations.

  • Removes the generic newFromHash helper function and inlines hash computation directly in NewV3 and NewV5
  • Pre-allocates hash result buffer with make([]byte, 0, capacity) to avoid allocations in h.Sum(nil)
  • Uses named return values to leverage zero-value initialization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov

codecov Bot commented Sep 25, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f37c04d) to head (7da2e32).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #221   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          516       517    +1     
=========================================
+ Hits           516       517    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cameracker
cameracker requested a review from Copilot September 25, 2025 01:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@cameracker
cameracker merged commit e1fb84e into gofrs:master Sep 25, 2025
7 checks passed
@cameracker

Copy link
Copy Markdown
Collaborator

@anatoly-kussul thank you very much for this contribution, and apologies it took me a while to get to it. Nice change! Simple but impactful perf improvements are appreciated.

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.

3 participants