Skip to content
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

feat: Faster random sampling #9655

Merged
merged 7 commits into from
Nov 1, 2024
Merged

feat: Faster random sampling #9655

merged 7 commits into from
Nov 1, 2024

Conversation

Rumata888
Copy link
Contributor

@Rumata888 Rumata888 commented Nov 1, 2024

This PR:

  1. Replaces the mechanism of sampling random data from using random_device to directly using the system APIs
  2. Removes an accidental unchecked random field element transformation that got in due to a dirty branch in feat: Faster randomness sampling for field elements #9627

169x in Native, 35x in wasm
Before, native:
image
After:
image

Before, wasm:
image
After:
image

@Rumata888 Rumata888 self-assigned this Nov 1, 2024
@Rumata888 Rumata888 requested a review from charlielye November 1, 2024 17:05
@Rumata888 Rumata888 force-pushed the is/even_faster_random branch from 2b6412f to 20c0bd5 Compare November 1, 2024 17:05
@Rumata888 Rumata888 force-pushed the is/even_faster_random branch from 20c0bd5 to 417c055 Compare November 1, 2024 17:09
hi.self_reduce_once();
hi.self_reduce_once();
hi.self_reduce_once();
lo = engine->get_random_uint256();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I restored the version that Zac checked in a previous PR. Accidentally got in an unchecked PR in there

#ifndef NO_MULTITHREADING
std::unique_lock<std::mutex> lock(random_buffer_mutex);
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like it'd overall work better if the random buffer and random buffer offset were thread_local, then we wouldn't need any locking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll switch. Hope we don't get a situation where we sample very few elements in new threads all the time

Copy link
Collaborator

Choose a reason for hiding this comment

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

with the thread pool, that wouldn't be the case

@ludamad
Copy link
Collaborator

ludamad commented Nov 1, 2024

Still have a style complaint that we added two related global variables not bundled in a struct, but approving

@Rumata888 Rumata888 merged commit 969a3f0 into master Nov 1, 2024
41 of 46 checks passed
@Rumata888 Rumata888 deleted the is/even_faster_random branch November 1, 2024 21:18
TomAFrench added a commit that referenced this pull request Nov 4, 2024
* master: (81 commits)
  feat: Encode static error strings in the ABI (#9552)
  chore: redo typo PR by donatik27 (#9693)
  chore: update install instructions for foundry to display version of rust to install (#9653)
  chore: disable bench upload until #9692
  fix: earthly-ci in bench-e2e (#9689)
  chore: redo typo PR by cypherpepe (#9687)
  chore: redo typo PR by youyyytrok (#9686)
  chore: redo typo PR by mdqst (#9685)
  chore: redo typo PR by mdqst (#9684)
  feat: adding tags to encrypted logs (#9566)
  fix: enable gerousia e2e test (#9677)
  git subrepo push --branch=master noir-projects/aztec-nr
  git_subrepo.sh: Fix parent in .gitrepo file. [skip ci]
  chore: replace relative paths to noir-protocol-circuits
  git subrepo push --branch=master barretenberg
  chore: redo typo PR by dsarfed (#9667)
  fix: bench e2e jobs (#9662)
  fix: Fix random for Mac users  (#9670)
  feat: Graph methods for circuit analysis (part 1) (#7948)
  feat: Faster random sampling (#9655)
  ...
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