Skip to content

Move calls to FeatureFlag.enabled to class-load time #125885

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

Merged
merged 2 commits into from
Apr 10, 2025

Conversation

original-brownbear
Copy link
Member

Random realization after adding my first feature flag today: we tend to create the flag instance and call this method everywhere. This doesn't compile the same way as a real boolean constant unless you're running with -XX:+TrustFinalNonStaticFields. For most of the code spots changed here that's irrelevant but at least the usage in the mapper parsing code is a little hot and gets a small speedup from this potentially.
Also we're simply wasting some bytes for the static footprint of ES by using the FeatureFlag indirection instead of just a boolean.

I noticed that we tend to create the flag instance and call this method
everywhere. This doesn't compile the same way as a real boolean constant
unless you're running with `-XX:+TrustFinalNonStaticFields`.
For most of the code spots changed here that's irrelevant but at least
the usage in the mapper parsing code is a little hot and gets a small
speedup from this potentially.
Also we're simply wasting some bytes for the static footprint of ES by
using the `FeatureFlag` indirection instead of just a boolean.
@original-brownbear original-brownbear added >non-issue :Core/Infra/Core Core issues without another label labels Mar 28, 2025
@original-brownbear original-brownbear requested a review from a team as a code owner March 28, 2025 18:32
@elasticsearchmachine elasticsearchmachine added Team:Core/Infra Meta label for core/infra team v9.1.0 labels Mar 28, 2025
@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.

Looks good. Although it seems now the object is just created to call isEnabled(), perhaps the entirety could be a static helper method akin to Boolean.getBoolean?

@original-brownbear
Copy link
Member Author

Thanks Ryan!

Yea definitely this should never have been objects. I'll see if I can find time for a follow up for that. I can't do that here easily since there's still some use of the actual objects left (we're looking them up from a map somewhere) so it's a slightly bigger change. This deals with some performance weirdness just fine for now though :)

@original-brownbear original-brownbear added auto-backport Automatically create backport pull requests when merged v8.19.0 labels Apr 10, 2025
@original-brownbear original-brownbear merged commit dd1db50 into elastic:main Apr 10, 2025
17 checks passed
@original-brownbear original-brownbear deleted the flags-to-boolean branch April 10, 2025 23:46
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 125885

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged backport pending :Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants