Skip to content

all: replace math/rand with math/rand/v2 #6732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 15, 2025
Merged

Conversation

seankhliao
Copy link
Contributor

@seankhliao seankhliao commented May 4, 2025

Update to new stdlib apis.

The new Float64 is uniform, which resolves a long comment.

https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/math/rand/v2/rand.go;l=209

// There are exactly 1<<53 float64s in [0,1). Use Intn(1<<53) / (1<<53).
return float64(r.Uint64()<<11>>11) / (1 << 53)

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/trace
cpu: 12th Gen Intel(R) Core(TM) i7-1260P
                                 │   old.txt    │               new.txt                │
                                 │    sec/op    │    sec/op     vs base                │
TraceStart/with_a_simple_span-16   387.1n ±  5%   306.8n ± 15%  -20.73% (p=0.000 n=10)
TraceStart/with_several_links-16   542.2n ±  5%   501.0n ±  2%   -7.61% (p=0.000 n=10)
TraceStart/with_attributes-16      521.4n ± 14%   571.6n ±  6%   +9.64% (p=0.009 n=10)
geomean                            478.3n         444.6n         -7.05%

                                 │  old.txt   │               new.txt               │
                                 │    B/op    │    B/op     vs base                 │
TraceStart/with_a_simple_span-16   528.0 ± 0%   528.0 ± 0%       ~ (p=1.000 n=10) ¹
TraceStart/with_several_links-16   704.0 ± 0%   704.0 ± 0%       ~ (p=1.000 n=10) ¹
TraceStart/with_attributes-16      784.0 ± 0%   784.0 ± 0%       ~ (p=1.000 n=10) ¹
geomean                            663.0        663.0       +0.00%
¹ all samples are equal

                                 │  old.txt   │               new.txt               │
                                 │ allocs/op  │ allocs/op   vs base                 │
TraceStart/with_a_simple_span-16   2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
TraceStart/with_several_links-16   3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=10) ¹
TraceStart/with_attributes-16      4.000 ± 0%   4.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                            2.884        2.884       +0.00%
¹ all samples are equal

@seankhliao seankhliao force-pushed the rand branch 2 times, most recently from 35d4e2d to 4f8b26e Compare May 4, 2025 18:14
@dmathieu dmathieu added the Skip Changelog PRs that do not require a CHANGELOG.md entry label May 5, 2025
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Are we sure that we do not want a changelog entry for this change?

@seankhliao
Copy link
Contributor Author

I thought about it but it didn't seem to fit the rest of the changelog as there's no real observable change from the end user perspective.

@pellared
Copy link
Member

pellared commented May 8, 2025

I thought about it but it didn't seem to fit the rest of the changelog as there's no real observable change from the end user perspective.

What about the fact that FixedSizeReservoir now uses a uniform random generator?
Is it not a fix/change so that we are going to be compliant with https://github.com/open-telemetry/opentelemetry-specification/blob/cdac03154c5b814a83689aecb97f82d6bbf7c0b2/specification/metrics/sdk.md?plain=1#L1190-L1192?

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Looks good overall. I especially like the ID generator fixes.

Please include benchmarks using benchstat in the PR descrition for the files changed that provide existing benchmarks.

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

🚀

@seankhliao
Copy link
Contributor Author

I added a benchstat comparison for the TraceStart benchmarks, not sure if anything else would be affected?

@dmathieu
Copy link
Member

Unless anyone objects, I will merge this in about 24 hours.

@dmathieu dmathieu merged commit a571c52 into open-telemetry:main May 15, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants