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

Remove allocations from TimeBasedUUIDGenerator #104584

Merged

Conversation

original-brownbear
Copy link
Member

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).

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).
@original-brownbear original-brownbear added >non-issue :Core/Infra/Core Core issues without another label labels Jan 19, 2024
@elasticsearchmachine elasticsearchmachine added v8.13.0 Team:Core/Infra Meta label for core/infra team labels Jan 19, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Member

@rjernst rjernst left a 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();
Copy link
Member

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?

Copy link
Member Author

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 :)

@original-brownbear
Copy link
Member Author

Thanks Ryan!

@original-brownbear original-brownbear merged commit 72c1e6c into elastic:main Jan 21, 2024
15 checks passed
@original-brownbear original-brownbear deleted the const-base64-encoder branch January 21, 2024 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants