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

Memory leak #201

Open
o-santi opened this issue Oct 27, 2022 · 1 comment
Open

Memory leak #201

o-santi opened this issue Oct 27, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@o-santi
Copy link
Contributor

o-santi commented Oct 27, 2022

The following program, taken from HVM's example on lambda arithmetic, converted to kdl (as done here) and run on KVM leaks space (does not properly clear all the stored data that wasnt used), which then stores unecessary data on the chain. The bigger the numeric operation, the bigger the leak.

This seems to be related with lambda encoded data (in this case, Scott encoded) being passed around, more specifically when multiple erased arguments are applied to other erased arguments (or something like this?). This error seems to be related with this problem on HVM, where the possible fix seems to make the runtime not lazy on some cases, and thus more investigation is needed to draw further conclusions.

@o-santi o-santi added the bug Something isn't working label Oct 27, 2022
@o-santi o-santi self-assigned this Oct 27, 2022
@o-santi
Copy link
Contributor Author

o-santi commented Oct 27, 2022

Very small example that shows this behaviour (using Scott encoded pairs) :

run {
  let new = @a @b @f ((f a) b);
  let first = @p (p @a @~ a);
  let secnd = @p (p @~ @b b);
  dup new1 new2 = new;
  dup p1 p2 = ((new1 #1) #2);
  (Done ((new2 (first p1)) (secnd p2)))
}

On current KVM, this run has size = 24 (instead of 0).
I'm 99% sure this has to do with when a lambda that has an erased argument is cloned and then applied to another term.

Scott encoding is not that useful inside KVM, since constructors are primitive, but continuation passing style is very much useful in this context (monads!), and will envolve a lot of erased-argument lambdas, which will probably cause some unexpected large memory leaks in some cases. I will try to find an example like this.

@steinerkelvin steinerkelvin moved this to ↻ In Progress in Kindelia Network Project Oct 31, 2022
@steinerkelvin steinerkelvin changed the title Space leak on lambda arithmetic Memory leak Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant