Skip to content

Slow wallet loading #161

@pavel-kokolemin

Description

@pavel-kokolemin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions