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

Huge heap memory increase (10x) when calling ic_cdk::storage::stable_restore() #212

Closed
alexeychirkov opened this issue Feb 21, 2022 · 0 comments · Fixed by #216
Closed

Comments

@alexeychirkov
Copy link

When calling ic_cdk::storage::stable_restore() there is obsolete heap memory increase (10x times more than stable memory size).

This always happens in ic-cdk/src/storage.rs line 76 because there is an error returned with dump of deserialiser (candid/src/de.rs line 104)

This issue does not depend on restored data structure.

roman-kashitsyn added a commit that referenced this issue Feb 24, 2022
This change removes the call to decoder.done() in stable_restore().

Rationale:

 * done() almost always returns an error because the input is likely
   to contain trailing zero bytes.

 * Calling done() has no effect on the return value.

 * The error that done() constructs contains the dump of the whole state,
   which causes the decoder to allocate huge amounts of memory.
   All of these allocations are unnecessary because stable_restore()
   throws away the error right away.

Fixes #212.
lwshang pushed a commit that referenced this issue Feb 24, 2022
This change removes the call to decoder.done() in stable_restore().

Rationale:

 * done() almost always returns an error because the input is likely
   to contain trailing zero bytes.

 * Calling done() has no effect on the return value.

 * The error that done() constructs contains the dump of the whole state,
   which causes the decoder to allocate huge amounts of memory.
   All of these allocations are unnecessary because stable_restore()
   throws away the error right away.

Fixes #212.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant