Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kskalski
Copy link

@kskalski kskalski commented Nov 11, 2025

Problem

  • rand crate with version >=0.9 fixes problem with gen function name colliding with keyword reserved in Rust 2024 edition (it doesn't strictly block Upgrade rust edition to 2024 #6203, but seems like a better way to hit two birds with one stone)
  • there are performance improvements in newer versions of rand
  • there are however many API breaking changes, but addressable as renames / import updates for production code

Due to the last point we might be better off with updating rand incrementally (compare with previous attempt of upgrading in #4721).

Summary of Changes

  • switch accounts-db to rand 0.9.2
  • switch dev dependency rand_chacha to 0.9.0 (closely coupled with rand, they both rely on same version of rand_core)
Performance

rand is mostly used in tests, comparison of their runtime:

  • PR
test result: ok. 624 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 28.91s

 Running tests/read_only_accounts_cache.rs (target/debug/deps/read_only_accounts_cache-4c2601e53cf50ede)
test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 11.12s

cargo +nightly-2025-06-23 bench --package solana-accounts-db --bench accounts
running 10 tests
test bench_concurrent_read_write                       ... bench:     773,307.62 ns/iter (+/- 315,471.86)
test bench_concurrent_scan_write                       ... bench:     768,964.80 ns/iter (+/- 344,317.74)
test bench_dashmap_iter                                ... bench:     197,803.35 ns/iter (+/- 1,568.51)
test bench_dashmap_par_iter                            ... bench:     163,446.24 ns/iter (+/- 9,036.01)
test bench_dashmap_single_reader_with_n_writers        ... ignored
test bench_delete_dependencies                         ... bench:   1,999,916.60 ns/iter (+/- 761,710.29)
test bench_load_largest_accounts                       ... bench:   5,656,484.20 ns/iter (+/- 43,204.14)
test bench_rwlock_hashmap_single_reader_with_n_writers ... ignored
test bench_sort_and_remove_dups                        ... bench:      29,782.58 ns/iter (+/- 145.07)
test bench_sort_and_remove_dups_no_dups                ... bench:      30,674.83 ns/iter (+/- 442.04)

test result: ok. 0 passed; 0 failed; 2 ignored; 8 measured; 0 filtered out; finished in 12.39s
  • master
Test result: ok. 624 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 28.93s

Running tests/read_only_accounts_cache.rs (target/debug/deps/read_only_accounts_cache-8346ec7bbb2df948)
test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 10.62s

running 10 tests
test bench_concurrent_read_write                       ... bench:     691,007.78 ns/iter (+/- 339,669.16)
test bench_concurrent_scan_write                       ... bench:     670,621.40 ns/iter (+/- 379,000.60)
test bench_dashmap_iter                                ... bench:     198,229.70 ns/iter (+/- 226.25)
test bench_dashmap_par_iter                            ... bench:     165,864.11 ns/iter (+/- 2,612.95)
test bench_dashmap_single_reader_with_n_writers        ... ignored
test bench_delete_dependencies                         ... bench:   1,326,333.00 ns/iter (+/- 19,858.66)
test bench_load_largest_accounts                       ... bench:   5,607,317.10 ns/iter (+/- 8,083.11)
test bench_rwlock_hashmap_single_reader_with_n_writers ... ignored
test bench_sort_and_remove_dups                        ... bench:      30,049.70 ns/iter (+/- 155.13)
test bench_sort_and_remove_dups_no_dups                ... bench:      31,657.24 ns/iter (+/- 126.11)

test result: ok. 0 passed; 0 failed; 2 ignored; 8 measured; 0 filtered out; finished in 13.72s

@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.9%. Comparing base (550789a) to head (c71bb7e).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9020   +/-   ##
=======================================
  Coverage    81.9%    81.9%           
=======================================
  Files         862      862           
  Lines      326917   326916    -1     
=======================================
+ Hits       267789   267852   +63     
+ Misses      59128    59064   -64     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kskalski kskalski marked this pull request as ready for review November 11, 2025 11:16
Copy link

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

Overall looks good to me. Thanks for doing this!


use rand::prelude::*;
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234);
let mut rng = StdRng::seed_from_u64(1234);

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Right, meaning it could generate different values for the same seed between platforms and minor releases. Do you think it could spoil the long-term comparisons on the test / benchmark results?

Choose a reason for hiding this comment

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

Do you think it could spoil the long-term comparisons on the test / benchmark results?

For the benchmarks, yeah. For the test, probably not, but may depend on the test.


I think this PR should be more narrowly focused on just upgrading rand to 0.9, and thus leaving the chacha parts as-is (since there's potential behavior changes when removing chacha).

Copy link
Author

Choose a reason for hiding this comment

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

There wee some version conflicts, so it might require updating rand_chacha or other crates versions thus actually expanding the scope of the PR, let me check again.

Copy link
Author

Choose a reason for hiding this comment

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

ok, since rand and rand_chacha come from the same repo and are coupled closerly (depend on rand_core), just moving that one to 0.9.0 version solved the issue and the diff is cleaner now.

HaoranYi
HaoranYi previously approved these changes Nov 11, 2025
Copy link

@HaoranYi HaoranYi left a comment

Choose a reason for hiding this comment

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

LGTM

@kskalski kskalski changed the title chore(accounts-db): switch to rand=0.9.2 and remove rand_chacha dependency chore(accounts-db): switch to rand=0.9.2 and rand_chacha=0.9 (dev dependency) Nov 11, 2025
@kskalski kskalski requested a review from brooksprumo November 11, 2025 23:54
Copy link

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

:shipit:

// Use SmallRng as it's faster than the default ChaCha and we don't
// need a crypto rng here.
let mut rng = SmallRng::from_entropy();
let mut rng = SmallRng::from_os_rng();

Choose a reason for hiding this comment

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

👍

From https://rust-random.github.io/book/update-0.9.html:

fn from_entropy was renamed to from_os_rng along with a new fallible variant, fn try_from_os_rng

@kskalski kskalski added this pull request to the merge queue Nov 12, 2025
Merged via the queue into anza-xyz:master with commit 93a9d2a Nov 12, 2025
55 checks passed
@kskalski kskalski deleted the ks/rand_accts_db branch November 12, 2025 01:12
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.

4 participants