-
Notifications
You must be signed in to change notification settings - Fork 33
use memoize to remove runtime error in graal native image #50
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together.
- core.memoize is fine, but mostly for being more thread-safe. I don't think we ever care to evict in this case, so we probably don't need to consider the various eviction strategies.
- Likewise, the thread "unsafe" aspect of plain
memoize
is that it might duplicate work, which is fine if it's still sufficiently faster than the alternatives - The test fn sleeps for 100 ms. If these results are in nanoseconds, that means sleep time dominates over cache management by orders of magnitude, which is going to make all the memoization methods perform about the same when it comes to the first time. To evaluate initial memoization performance, I don't think we really need a time-consuming fn.
- Minor note: I'm surprised that memo-memo is frequently slower than memo-fifo.
So far, it looks like plain memoize
may be fastest. I'm surprised that fast-memoize is 100x slower than it, though. Either it's truly from a different era (i.e., 8 years ago) or something's wrong.
(EDIT: removed the bit about pmap. After getting some sleep, it struck me that of course we want to test under parallel scenarios, even if it's more convoluted. )
@josh-7t Well, I've been playing around with it for the last hour, using Criterium for a second opinion (because Criterium factors in its own overhead), and the results are the same. I'm not sure why the ConcurrentHashMap-backed version is 1000x slower, but my guess is it's related to the wrapping/unwrapping of the value in a delay, or maybe the bookkeeping overhead in ConcurrentHashMap. I was worried the delay was necessary for certain behavior, but it's unwrapped immediately. It replaced some older code that swapped nils in and out with ::nil because ConcurrentHashMa can't store nulls, so I don't think it's relevant. I don't think it's worth investigating more deeply, so let's go with plain |
Just checking in, I've made the requested changes. Is this good to go in? |
Sorry, I moved to another country, and have been a bit distracted. Merging now. |
Hey, no worries. That's a big thing! |
See #48 for the error encountered in graal.
According to the simple benchmarks that I came up with it looks like
memoize
andfast-memoize
are very close in performance.I also benchmarked the different options available in https://github.com/clojure/core.memoize in case one of the caching strategies there is useful.