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

perf: split lengthy mutating methods into prepare() and finalize(). #183

Open
dan-da opened this issue Sep 10, 2024 · 0 comments
Open

perf: split lengthy mutating methods into prepare() and finalize(). #183

dan-da opened this issue Sep 10, 2024 · 0 comments
Labels
concurrency neptune-core async tasks should run concurrently without blocking eachother for long performance speed, optimization, concurrency, mem-usage

Comments

@dan-da
Copy link
Collaborator

dan-da commented Sep 10, 2024

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. prepare_claim_utxo_in_block(&self) -> updates
  2. finalize_claim_utxo_in_block(&mut self, updates)

(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.

@dan-da dan-da added concurrency neptune-core async tasks should run concurrently without blocking eachother for long performance speed, optimization, concurrency, mem-usage labels Sep 10, 2024
dan-da added a commit that referenced this issue Sep 17, 2024
dan-da added a commit that referenced this issue Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency neptune-core async tasks should run concurrently without blocking eachother for long performance speed, optimization, concurrency, mem-usage
Projects
None yet
Development

No branches or pull requests

1 participant