perf: split lengthy mutating methods into prepare() and finalize(). #183
Labels
concurrency
neptune-core async tasks should run concurrently without blocking eachother for long
performance
speed, optimization, concurrency, mem-usage
There are some methods that take &mut self and then perform lengthy operations. This means that they are holding the write-lock and blocking all other tasks from processing until they complete.
The two I am presently looking at are:
a. GlobalState::resync_membership_proofs_from_stored_blocks(&mut self)
b. WalletState::update_wallet_state_with_new_block(&mut self)
(a) is run every 59 seconds from a timer.
(b) is run every time a new block is received, approx every 10 minutes.
I was faced with this situation when writing a new method called claim_utxo_for_block(). I solved it by splitting the method into two:
(1) takes &self and performs the lengthy operations to gather all the necessary updates. It does this with only a read-lock so other tasks run currently with no problem.
(2) takes &mut self and the updates returned from (1). It quickly writes the updates and returns. so it holds the write-lock for the minimum possible time.
I am creating this issue as a reminder to myself to attempt this approach with (a) and (b), and scan for any others that could possibly benefit as well.
The text was updated successfully, but these errors were encountered: