Skip to content

runtime: swap im for imbl in StakesCache#10762

Merged
2501babe merged 1 commit intoanza-xyz:masterfrom
2501babe:20260222_imbl
Apr 10, 2026
Merged

runtime: swap im for imbl in StakesCache#10762
2501babe merged 1 commit intoanza-xyz:masterfrom
2501babe:20260222_imbl

Conversation

@2501babe
Copy link
Copy Markdown
Member

@2501babe 2501babe commented Feb 23, 2026

Problem

stakes cache is a bottleneck

Summary of Changes

replace im with imbl. the former has not been updated for years, the latter is a backwards-compat fork that is presently maintained and more optimized

in #10760 i add some very simple benches for epoch rewards and advancing the epoch. if they are to be believed, this speeds rewards up by 10% and epoch advance by 30%

before:

test bench_epoch_rewards_period ... bench: 352,109,145.90 ns/iter (+/- 56,468,574.76)
test bench_epoch_turnover       ... bench:  15,555,461.00 ns/iter (+/- 2,037,170.53

after:

test bench_epoch_rewards_period ... bench: 310,888,743.00 ns/iter (+/- 53,842,063.38)
test bench_epoch_turnover       ... bench:  10,845,295.30 ns/iter (+/- 1,171,299.93)

@2501babe 2501babe self-assigned this Feb 23, 2026
@2501babe 2501babe changed the title runtim: swap im for imbl in StakesCache runtime: swap im for imbl in StakesCache Feb 23, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.1%. Comparing base (82f55d7) to head (1d35234).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10762   +/-   ##
=======================================
  Coverage    83.1%    83.1%           
=======================================
  Files         858      858           
  Lines      321771   321771           
=======================================
+ Hits       267642   267643    +1     
+ Misses      54129    54128    -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vadorovsky vadorovsky self-requested a review February 23, 2026 11:21
@vadorovsky
Copy link
Copy Markdown
Member

I'll try to profile this whenever I have time.

@2501babe
Copy link
Copy Markdown
Member Author

2501babe commented Feb 23, 2026

similar proportional savings using Criterion with 1m stake 1k vote:

bench_epoch_turnover/HANA
                        time:   [70.475 ms 70.904 ms 71.412 ms]
                        change: [−56.279% −55.881% −55.446%] (p = 0.00 < 0.05)
                        Performance has improved.

Benchmarking bench_epoch_rewards_period/HANA: Warming up for 1.0000 s
Warning: Unable to complete 10 samples in 10.0s. You may wish to increase target time to 44.5s.
bench_epoch_rewards_period/HANA
                        time:   [3.6422 s 3.6790 s 3.7185 s]
                        change: [−12.773% −11.459% −10.109%] (p = 0.00 < 0.05)
                        Performance has improved.

@2501babe 2501babe force-pushed the 20260222_imbl branch 3 times, most recently from 66c9d4d to caa4d1b Compare March 3, 2026 05:31
@2501babe 2501babe force-pushed the 20260222_imbl branch 2 times, most recently from c992665 to bb0b6d1 Compare March 4, 2026 12:26
@2501babe 2501babe marked this pull request as ready for review March 4, 2026 16:56
@2501babe
Copy link
Copy Markdown
Member Author

2501babe commented Mar 4, 2026

@vadorovsky i landed the necessary solana-sdk work that was blocking this, so we can move forward on this any time we feel happy with it

@2501babe 2501babe force-pushed the 20260222_imbl branch 3 times, most recently from 92ad741 to 48fade9 Compare March 13, 2026 13:43
@kskalski
Copy link
Copy Markdown

kskalski commented Apr 3, 2026

Are we going to land this change or did it turn out to not be useful? I'm asking because I want to support wincode serialization of snapshots (which does serialization of structs holding the stakes map) and could focus on adding support for just one of those crates.

@2501babe
Copy link
Copy Markdown
Member Author

2501babe commented Apr 3, 2026

im in favor and think its up to @vadorovsky or @alessandrod

@alessandrod
Copy link
Copy Markdown

@kskalski could you help review?

I think switching is ok. The other crate is unmaintained. I did some profiling a few weeks ago and there was maybe a small regression somewhere but overall perf looks good. I say let's go for it and if we find issues we fix them, can't really depend on unmaintained code forever anyway.

@kskalski
Copy link
Copy Markdown

kskalski commented Apr 9, 2026

I will also compare the performance of into and from iterator that is part of serializing snapshots.

@2501babe 2501babe requested review from kskalski and removed request for vadorovsky April 9, 2026 16:38
Copy link
Copy Markdown

@kskalski kskalski left a comment

Choose a reason for hiding this comment

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

I compared profiles for:

  • deserializing snapshot - same perf, though im* isn't really visible there
  • serializing snapshot - there is a slight (11% -> 8.5% of cpu), but clear improvement iterating over the im hash map (a lot of the calls into aux code from Iterator::next is gone, so this part was clearly inlined / optimized)

Given benchmark results, other comparison and maintenance status of im I also think it will be good to merge.

@2501babe 2501babe added this pull request to the merge queue Apr 10, 2026
Merged via the queue into anza-xyz:master with commit d795b59 Apr 10, 2026
50 checks passed
@2501babe 2501babe deleted the 20260222_imbl branch April 10, 2026 08:43
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.

5 participants