Skip to content

Replace fastrand with rand/v2 package - #8534

Closed
Amirali-Amirifar wants to merge 1 commit into
nats-io:mainfrom
Amirali-Amirifar:remove-fastrand
Closed

Replace fastrand with rand/v2 package#8534
Amirali-Amirifar wants to merge 1 commit into
nats-io:mainfrom
Amirali-Amirifar:remove-fastrand

Conversation

@Amirali-Amirifar

Copy link
Copy Markdown

This pull request replaces the internal fastrand package with Go's standard library math/rand/v2.

The changes:

  1. Replace internal/fastrand usage with math/rand/v2.
  2. Migrate existing math/rand (v1) usage in the affected files to math/rand/v2.
  3. Remove the now-unused internal/fastrand package.
  4. Apply gofmt formatting to the modified files.

This follows the approach taken by other Go projects, such as CockroachDB Pebble Which is the origin of this fastrand package cockroachdb/pebble#4018

@Amirali-Amirifar
Amirali-Amirifar requested review from a team as code owners August 29, 2026 13:51
@github-actions

Copy link
Copy Markdown

Please review the CONTRIBUTING.md guide as some commits are missing Signed-off-by: in their commit messages.

To correct, please amend the following commits and force-push:

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81877d6647

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread server/jetstream_benchmark_test.go
Comment thread server/jetstream_benchmark_test.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dbca1e5481

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread server/jetstream_benchmark_test.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2db437fb6d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread server/jetstream_benchmark_test.go Outdated
Signed-off-by: Amirali Amirifar <amirali.amirifar@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e811988b1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

filters := make([]string, 0, bc.filters)
for len(filterDomains) < bc.filters {
domain := domains[rng.Intn(len(domains))]
domain := domains[rand.IntN(len(domains))]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep concurrent filter selection deterministically seeded

When this benchmark runs multiple consumer goroutines, selecting domains through the package-level generator makes each consumer's filter set depend on goroutine scheduling and vary between runs. Because overlap among concurrent consumers changes how many consumers process the same subjects, benchmark deltas can reflect a different concurrent workload rather than the code under test. Preserve the previous per-consumer RNG behavior by creating a locally seeded ChaCha8 generator from seed + consumerId and passing it into this helper.

Useful? React with 👍 / 👎.

@Amirali-Amirifar Amirali-Amirifar Aug 29, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is it really significant? does it require deterministic run?

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.

1 participant