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

memoization of step heaps, effectively preallocating weak arrays #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nilsbecker
Copy link

this is another performance improvement suggestion. it's entirely possible that this breaks the JS backend. i have not tried.

weak array creations are reduced further by keeping old weak array heaps from previous steps around in a primitive stack. in my benchmarks where steps are fired in a tight loop, the commit cee407f decreased the runtime of a simulation between 20 and 40%. similar improvements are also seen in the minibenchmark https://gist.github.com/nilsbecker/2ec8d0a136e2fcc20184#file-react_minibenchmark-ml . compared to react 1.2.0, in my specific use cases, this in some cases gives a speedup of around 2 times.

@dbuenzli
Copy link
Owner

might be considered evil

It's not evil but it invalidates the thread safety properties mentioned in the documentation... Interesting though.

@nilsbecker
Copy link
Author

i see. i guess to make something like this thread safe it would be better to work with immutable values? not sure how this would be done, or whether it can be done efficiently. about speed: i noticed that the speedup factor is larger when the call graph is small. it seems that a constant, relatively small overhead per step creation is removed, and this is most noticeable for small call graphs.

@nilsbecker nilsbecker changed the title memoization of heap stacks, effectively preallocating weak arrays memoization of step heaps, effectively preallocating weak arrays Jan 26, 2015
nilsbecker and others added 4 commits November 30, 2021 13:28
the idea was to save on gc load by letting weak arrays expire by themselves

test.ml passes. the non-emptyness of the arrays above Wa.len does not seem to be a problem
this saves a lot of allocation/gc of weak arrays and gives speedups up to 40% in overhead dominated simulation tests
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 this pull request may close these issues.

2 participants