spruceid / didkit

A cross-platform toolkit for decentralized identity.
https://www.spruceid.dev/didkit/didkit
Apache License 2.0
275 stars 76 forks source link

High memory usage #301

Open JGiter opened 2 years ago

JGiter commented 2 years ago

Using either prepareIssuePresentation or completeIssuePresentation from @spruceid/didkit-wasm-node in class definition increases memory usage by 500 mb. Issue can be reproduced with simple class

const didkit = require('@spruceid/didkit-wasm-node');

class Verifier {
  prepareIssuePresentation(
    presentation,
    linked_data_proof_options,
    public_key
  ) {
    return didkit.prepareIssuePresentation(
      presentation,
      linked_data_proof_options,
      public_key
    );
  }
}

This happens only once - during the first reading of the class and lasts about 10 seconds

sbihel commented 2 years ago

I can't reproduce it locally. Could you give us the Node version you're using, the environment, and an example VP?

JGiter commented 2 years ago

I am using Node 16 on Ubuntu 20.04.4. To reproduce it I don't even create VP, just run script with code above

jrhender commented 2 years ago

@sbihel

I can't reproduce it locally.

Which Node version were you using when trying to reproduce? Perhaps we can try with your version

sbihel commented 2 years ago

Sorry for not keeping you updated. I was previously looking at the heap, but indeed the RSS is large. Although my observation is that it's the instantiation (import) of didkit that's causing the increase in memory, and it never goes down.

Node 18 performs noticeably better. Otherwise, I'm still trying to figure out if it's the compiled code, or the embedded data that's the issue -- but I'm not very hopeful I'll be able to change anything in that regard. Other options include compiling to ASM or making a custom build of ssi/didkit which includes only what you need.

jrhender commented 2 years ago

Thanks @sbihel

Although my observation is that it's the instantiation (import) of didkit that's causing the increase in memory, and it never goes down.

I guess you observed this when using a Node version lower than v18? Do you recall what the magnitude of RSS when doing this test with a lower version? Was it around the "500 mb" that @JGiter and I have observed?

We are trying with Node v18 and will report back.

sbihel commented 2 years ago

I guess you observed this when using a Node version lower than v18?

All of them actually.

Do you recall what the magnitude of RSS when doing this test with a lower version?

Indeed, it was around 500MB with v16 and v17. With v18 it was around 200MB.