Skip to content

Conversation

@wpessers
Copy link
Contributor

Use crypto/rand's Read method directly. Instead of reinitializing and seeding the rng on each span / trace id generation. Saving:

  1. Heap allocations
    • rand.NewSource(rngSeed)
    • rand.New(...)
  2. Some init logic - CPU time
  3. Probably negligible but function call overhead of calling rand.NewSource(rngSeed) and rand.New(...)

What remains now is basically a very efficient syscall, with no heap allocations.

@wpessers wpessers requested a review from a team as a code owner December 21, 2025 22:05
@wpessers
Copy link
Contributor Author

Noticed this in the existing code when reviewing changes from #2058

@wpessers wpessers added enhancement New feature or request go Pull requests that update Go code labels Dec 21, 2025
Copy link
Contributor

@herin049 herin049 left a comment

Choose a reason for hiding this comment

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

LGTM

@wpessers wpessers merged commit dc40760 into open-telemetry:main Dec 26, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants