-
Notifications
You must be signed in to change notification settings - Fork 57
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
Bad performance on recursive tuple/list deconstruction #394
Comments
Workaround for one of the probably most critical cases, counting of elements in a collapse: https://gist.github.com/patham9/aa3e93bb369e3fc1660cb473e7e74b55 |
This isn’t fundamental to the issue at hand, and you may already be doing this, but… Building hyperon with |
I have looked at the speed of this example in minimal MeTTa interpreter and there the recursive function call is transformed to the deeply nested atom which contains the interpretation plan. The number of nested levels is a linear function from recursion depth. When interpreter evaluates this atom it unwinds the nested atoms on each step to extract the leaf atom and evaluate it. Thus the overall number of atoms to be deconstructed/constructed during evaluation is a sum of arithmetic progression and it grows quadratically when number of nested levels grows linearly. I believe something similar happens in Rust interpreter with nested plans but I am not sure. |
I don't think we need to fix it in Rust interpreter but we should fix it in minimal MeTTa interpreter. One way to do it is to eliminate construction/deconstruction of atoms and instead replace the leaf atom during evaluation. Unfortunately it is doesn't work for the case when leaf atom is evaluated into few alternatives. In such case we need to copy the overall plan which is costly. Also we could change the representation of the plan to simplify getting currently evaluated atom and reuse the further plan instead of copying it when atom is evaluated into list of alternatives. |
Performance measurements on current main (1c4bc52) on AMD Ryzen 7 5800U. Both Rust and Python versions was build in release mode.
I additionally tested Rust version on 69a698f which is state of the code before #745 is merged. Here
Overall these measures show that performance is better comparing to the time when the issue was raised except |
This issue is to investigate the perfomance in case when list or tuple is recursively deconstructed.
According to @patham9 measurements:
takes 2.8 seconds
takes 3 seconds
and this 4.8 seconds for me.
Same with tuples 3.8 seconds:
The text was updated successfully, but these errors were encountered: