-
Notifications
You must be signed in to change notification settings - Fork 94
Short circuit value cache look up to avoid object allocations #109
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
… the value cache lookups
@Override | ||
public synchronized Throwable fillInStackTrace() { | ||
return this; | ||
} |
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 is magic - the exception has no stack trace (we don't want one) AND its fast to allocate because of this.
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.
Does it need it to be synchronized?
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.
No - it is in the base class. I will change this
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.
Awesome!
@Override | ||
public synchronized Throwable fillInStackTrace() { | ||
return this; | ||
} |
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.
Does it need it to be synchronized?
@@ -20,37 +22,55 @@ | |||
@Internal |
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.
Maybe promote it to public? We expose a public static final NOOP
which may be of use to library consumers
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.
The NOOP is a default impl for never caching. I want it to stay that way. There is no real useful code here honestly for library consumers
/** | ||
* a no op value cache instance | ||
*/ | ||
public static final NoOpValueCache<?, ?> NOOP = new NoOpValueCache<>(); |
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.
If we make it public:
Introduce a private constructor? + Builder method for type safety?
Just realised that if we open it up (and make it final), people cannot reuse the magic values like |
Yeah I don't really want them do this on a @internal class - honestly if someone makes a ValueCache then we would expect them to NOT ever throw short circuit exceptions- I mean they can but unlikely |
I agree, thank you for the quick action :) |
The original PR : #108 shows we are allocating too many objects.
This takes it further by introducing a fast exception to allow a
ValueCache
to short circuit out of a look up.This is then used by the default NoopValueCache and hences saves memory and processing for every one NOT using a ValueCache