-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Remove allocations from TimeBasedUUIDGenerator #104584
Remove allocations from TimeBasedUUIDGenerator #104584
Conversation
No need to use a capturing lambda here, als no need to re-create the base64-no-padding encoder over and over. Empirically, saves about 0.5% of all allocations in the http_logs indexing step interestingly enough (according to async profiler).
Pinging @elastic/es-core-infra (Team:Core/Infra) |
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.
LGTM, one unrelated question.
@@ -35,6 +35,8 @@ class TimeBasedUUIDGenerator implements UUIDGenerator { | |||
assert SECURE_MUNGED_ADDRESS.length == 6; | |||
} | |||
|
|||
private static final Base64.Encoder BASE_64_NO_PADDING = Base64.getUrlEncoder().withoutPadding(); | |||
|
|||
// protected for testing | |||
protected long currentTimeMillis() { | |||
return System.currentTimeMillis(); |
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.
Unrelated to your change: is there a reason this generator can't use the cached version of current time from ThreadPool?
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.
I guess it's a little bothersome code wise, because we use this thing as a static singleton and now it would have a non-static dependency on the threadpool.
Also, and I didn't do the math here, theoretically though probably hard in practice ... if someone sets a very long polling interval on the cache time, that would maybe introduce some chance of collision? Probably not still annoying to adjust this to depend on the pool :)
Thanks Ryan! |
No need to use a capturing lambda here and also no need to re-create the base64-no-padding encoder over and over.
Empirically, saves about 0.5% of all allocations in the http_logs indexing step interestingly enough (according to async profiler).