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
Replaced SoftReference with WeakReference for better performance #151
Conversation
but with WeakReference there may be no point to memoize at all: depending what you do with it, the memoized result can be garbaged really fast, even before a second iteration on the stream where memorization is useful. |
We use a cache of parsed expressions in production ( |
I think there is no general rule, it depends of how expensive it is to re-compute cached values and how frequently you need them. Maybe we need the three memo implementation to let the user chose the most appropriate one:
It is totally possible that for most use cases of streams weakMemo give the best results. |
What I meant is that we should not change the current |
+1 for adding three distinct methods and removing memo(). |
So, I think there should be three methods:
See my changes. |
@mperry can we change memo() memory behaviour without a full deprecation cycle? |
How about we keep memo(), but add an overload for it that passes in the e.g. then memo() would be implemented as: memo(Memo.weakReference) or whichever behavior you want as default.
|
I don't see any benefits of it |
… StackOverflow. Added Ordering.reverse(), Ord.reverse().
} | ||
}; | ||
} | ||
}, value(List.<A>nil())); |
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.
This caused StackOverflow
…Buffer.prependToList().
@@ -625,18 +624,18 @@ public final void foreachDoEffect(final Effect1<A> f) { | |||
* @return A new list that has appended the given list. | |||
*/ | |||
public final List<A> append(final List<A> as) { | |||
return fromList(this).append(as).toList(); | |||
return Buffer.fromList(this).prependToList(as); |
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.
List.append() was O(n+m). I made it O(n)
I agree with @techtangents, I think we should provide a default memo implementation and then other options to choose from a hard, soft and weak implementation. Whether this is separate hard, soft and weak methods or a parameter to memo does not matter too much. |
@jbgi we can change the implementation of |
I think this issue is complete enough to merge. I created #153 to handle hard, soft, weak and default memo implementations. |
Replaced SoftReference with WeakReference for better performance
Benchmark:
The result with SoftReference:
WeakReference:
SoftReference is about 70 times slower.
I also performed a profiling session with JVisualVM. With SoftReference there are 125 collections total and garbage collection took 23 seconds! With WeakReference - 29 collections and 25 milliseconds.