Skip to content

Speed up Version Checks #62216

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 3 commits into from
Sep 10, 2020

Conversation

original-brownbear
Copy link
Member

@original-brownbear original-brownbear commented Sep 10, 2020

Found randomly this while looking into where we're using large amounts of code cache/meta-space for an SDH:

The fromId method would show up in profiling and JIT analysis as not-inlinable because it's too large
in the contexts it's used in (deserialisation + transport header checks) in many cases and was consuming a surprising amount of cycles for computing the
min compat versions.

-> extract cold path from fromId to make JIT happy and cache minimum compatible versions to fields.

The `fromId` method would show up in profiling and JIT analysis as not-inlinable because it's too large
in the contexts it's used in in many cases and was consuming a surprising amount of cycles for computing the
min compat versions.

-> extract cold path from `fromId` to make JIT happy and cache minimumg compatible versions to fields.
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Sep 10, 2020
Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should add the ability to pass in the minimum compatibility versions for the already declared versions?

@@ -285,6 +286,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
static final List<Version> DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class));
}

// lazy initialized because we don't yet have the declared versions ready when instantiating the cached Version
// instances
private Version minCompatVersion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically shouldn't we declare these as volatile?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically shouldn't we declare these as volatile?

I figured no because we don't actively deduplicate this value so if we recompute it a few times (and realistically this is probably almost never going to happen) at startup it doesn't hurt but we pay the overhead in method size for volatile forever. But this was coded wrong even under that assumption now that I look at it again. I pushed 153763a so that it's safe even if out of order reads were to ever occur.

@original-brownbear
Copy link
Member Author

I wonder if we should add the ability to pass in the minimum compatibility versions for the already declared versions?

I tried this and it's painful to do that from the current code because if you want the same deduplicate this solution gives you, you'll have to be very careful about the order in which you initialize the fields. (and more importantly it adds new overhead for maintaining the class as well because currently we automatically get the min compatible versions right from the declared constants). Not sure it's worth it, the performance difference should be trivial but it looks like it makes things more complex.

Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@original-brownbear
Copy link
Member Author

Thanks Jay!

@original-brownbear original-brownbear merged commit c94f5b9 into elastic:master Sep 10, 2020
@original-brownbear original-brownbear deleted the faster-id-looks branch September 10, 2020 18:50
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Sep 10, 2020
The `fromId` method would show up in profiling and JIT analysis as not-inlinable because it's too large
in the contexts it's used in in many cases and was consuming a surprising amount of cycles for computing the
min compat versions.

-> extract cold path from `fromId` to make JIT happy and cache minimumg compatible versions to fields.
original-brownbear added a commit that referenced this pull request Sep 10, 2020
The `fromId` method would show up in profiling and JIT analysis as not-inlinable because it's too large
in the contexts it's used in in many cases and was consuming a surprising amount of cycles for computing the
min compat versions.

-> extract cold path from `fromId` to make JIT happy and cache minimumg compatible versions to fields.
@original-brownbear original-brownbear restored the faster-id-looks branch January 6, 2021 14:08
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 v7.10.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants