Blockstream / Blockstream/lwk

Slow wallet loading

Open
#161 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
111
Forks
60
Avg merge
1h 32m
Merged PRs (30d)
1

Description

I'm running a testnet LWK wallet with the legacy FS store.
There are 2075 transactions in total and 4607 update files in the enc_cache folder.
Recently I noticed that the wallet loading became quite slow.
It now takes about 29 seconds to load the wallet in the release build.
I attached a profiler and saw that the bottleneck is in this line:

```
let mut vec: Vec<_> = self.timestamps.iter().collect();
vec.sort(); // This line takes most of the time, 29 seconds in my case
vec.hash(state);
```

After I changed it to this (to prevent extra indirection):
```
let mut vec: Vec<(u32, u32)> = self.timestamps.clone().into_iter().collect();
```
It took about 18 seconds to load the wallet.

And after I commented out this code:
```
if self.wollet_status() != update.wollet_status {
return Err(Error::UpdateOnDifferentStatus {
wollet_status: self.wollet_status(),
update_status: update.wollet_status,
});
}
```
It took less than 2 seconds to load the wallet.

Here is my cache size at the end:
all_txs size: 2075
scripts size: 2118
heights size: 2118
unblinded size: 2118
timestamps size: 286064

Cache::hash is called 4607 times (once per an update file).
So in my case, LWK is sorting up to 286064 elements 4607 times on loading.
I think this should be fixed.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.