plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

Stronghold.load() is slow

Open Iraijus opened this issue 1 year ago • 20 comments

In my JS code, I run the following code:

appDataDir()
.then(async dir => {
  console.log(dir)
  const vaultPath = `${dir}/vault.hold`;
  const vaultPassword = 'vault_password';
  const stronghold = await Stronghold.load(vaultPath, vaultPassword);
  console.log("TEST");
})

The time between the first and second log is always somewhere between 1 and 2 minutes. Is there a reason why Stronghold.load() is so slow for me?

Iraijus avatar Nov 13 '24 20:11 Iraijus

Nevermind. I'm still not sure what the issue was, but clearing the app's storage, though I had already tried that before, solved the issue for now.

Iraijus avatar Nov 13 '24 21:11 Iraijus

Apparently, it only becomes slow after saving a value.

Iraijus avatar Nov 13 '24 21:11 Iraijus

I'm having trouble with the underlying iota_stronghold being slow as well. Also typically between 1-2 minutes.

UrsDeSwardt avatar Nov 14 '24 10:11 UrsDeSwardt

In case anyone else is struggling with this, I was able to get the underlying iota_stronghold working smoothly by downgrading the version to 1.0.5.

UrsDeSwardt avatar Nov 15 '24 12:11 UrsDeSwardt

I also have this issue.

lindongchen avatar Nov 16 '24 09:11 lindongchen

It seems that it is only slow for me in debug target, but not release. Is this also the case for you?

gabriel-le avatar Nov 19 '24 13:11 gabriel-le

@gabriel-le Yes, it's the same here.

almeidaz avatar Nov 20 '24 15:11 almeidaz

I went into IOTA's discord and found someone raising up the same issue, one of the members asked to run the program in --release mode, which does makes it faster. But didn't provide any other details

Ripwords avatar Nov 25 '24 16:11 Ripwords

I went into IOTA's discord and found someone raising up the same issue, one of the members asked to run the program in --release mode, which does makes it faster. But didn't provide any other details

yes in release mode it's faster.

ahkohd avatar Nov 25 '24 21:11 ahkohd

Running in release mode does make things a bit more inconvenient.

Just as a workaround, I created a simple class with getKey, setKey and removeKey methods. Using env variables to check if I'm in DEV or PROD if in DEV I use localStorage just to quickly test without having to wait, and only in PROD will be using stronghold.

Ripwords avatar Nov 28 '24 03:11 Ripwords

Running in release mode does make things a bit more inconvenient.

Just as a workaround, I created a simple class with getKey, setKey and removeKey methods. Using env variables to check if I'm in DEV or PROD if in DEV I use localStorage just to quickly test without having to wait, and only in PROD will be using stronghold.

yes, this is very neat.

ahkohd avatar Nov 29 '24 20:11 ahkohd

i'm facing the same issue it works fine in release mode but too slow in development mode using @Ripwords method seems to be a temporary fix to help focus on other things

kthehatter avatar Jan 20 '25 20:01 kthehatter

I am facing the same issue too, too slow in development mode

xiaohulu avatar Feb 12 '25 23:02 xiaohulu

I also noticed something strange, the memory keeps increasing by factor of 20-30 MB, about 16 times (480mb) : everytime i called the load method.

Image

endrik-exe avatar Feb 16 '25 04:02 endrik-exe

I also noticed something strange, the memory keeps increasing by factor of 20-30 MB, about 16 times (480mb) : everytime i called the load method.

Image

@endrik-exe is this in dev mode or prod mode? If prod I will need to remove it from my project.

HuakunShen avatar Feb 16 '25 10:02 HuakunShen

@HuakunShen This is dev mode, haven't tested it in prod yet.

endrik-exe avatar Feb 16 '25 10:02 endrik-exe

Does anyone know what the underlying problem is? Since this was tagged as upstream, I checked the issues on the stronghold.rs repo, but couldn't find anything related.

Deano217 avatar May 01 '25 10:05 Deano217

I've confirmed that this issue occurs only in debug mode, everything works fine in release. While it's just speculation, the root cause may be related to unoptimized cryptographic operations (encryption/decryption). Given that both the load() and save() methods are affected, this seems like a reasonable assumption. The thing is that this impacts negatively the development experience.

GeorgeGkas avatar May 08 '25 17:05 GeorgeGkas

Issue seems to be with the scrypt crate, which is a dependency of iota-crypto. Try adding this to Cargo.toml

[profile.dev.package.scrypt]
opt-level = 3

yunger7 avatar May 30 '25 21:05 yunger7

Issue seems to be with the scrypt crate, which is a dependency of iota-crypto. Try adding this to Cargo.toml

[profile.dev.package.scrypt] opt-level = 3

Works for my too!

Max-Loo avatar Oct 31 '25 08:10 Max-Loo