snarkVM icon indicating copy to clipboard operation
snarkVM copied to clipboard

[Perf] Don't recreate ReadOptions when querying the database

Open ljedrz opened this issue 10 months ago • 7 comments

Heap profiling indicates that plenty of allocations currently come from the use of rocksdb_readoptions_create, which is an FFI function called internally from get_pinned. This can easily be avoided by creating an instance of ReadOptions just once and reusing it via get_pinned_opt, which is the equivalent of get_pinned with a &ReadOptions parameter.

This change reduces (in a 15-minute run consisting of 4 --dev validators) the average number of allocations per second in a dev node that doesn't produce txs by roughly 30%, which is beneficial for the performance of any heap allocator.

ljedrz avatar Apr 22 '24 17:04 ljedrz

under what conditions do you see the reduction? Is it just normal operation of a node minus any load?

The difference was measured for a --dev 2 node which doesn't produce txs, but participates in consensus.

Would it be possible to profile this under heavy read load?

I requested a devnet run to see the impact with more transactions.

ljedrz avatar Apr 23 '24 07:04 ljedrz

Performed some memory profiling with ~2.5 hours of 25 TPS here. After the test, snarkOS maximum memory usage was reduced by 8% and average memory usage was reduced by 4.4% through this PR (maximum/average of all 10 nodes).

kpandl avatar Apr 23 '24 14:04 kpandl

A devnet test of this to profile has been kicked off

iamalwaysuncomfortable avatar Apr 23 '24 18:04 iamalwaysuncomfortable

Observations based on devnet metrics:

  • memory use is a bit lower, but there is still growth
  • log frequency is up, suggesting higher average throughput
  • average block lag is down, and its spikes are much lower
  • number of threads appears to be a bit down
  • minor page faults are reduced slightly

Overall, this change results in some small performance wins, and its effects are more significant with workloads that involve many database reads.

ljedrz avatar Apr 24 '24 11:04 ljedrz

I will await for approvals from reviewers prior to merging this one.

howardwu avatar Apr 24 '24 22:04 howardwu

Update: the same can be done with WriteOptions; the win is smaller, as we write less frequently.

ljedrz avatar Apr 26 '24 13:04 ljedrz

@joske can you also review this PR?

howardwu avatar Apr 29 '24 22:04 howardwu