Skip to content

Commit a138e0e

Browse files
Scott Somervillejasontedor
authored andcommitted
Compute declared versions in a static block
This method is called often enough (when computing minimum compatibility versions) that the reflection and sort can be seen while profiling. This commit addresses this issue by computing the declared versions exactly once. Relates #28661
1 parent 9a5199f commit a138e0e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

server/src/main/java/org/elasticsearch/Version.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public class Version implements Comparable<Version> {
163163
+ org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]";
164164
}
165165

166+
private static class DeclaredVersionsHolder {
167+
static final List<Version> DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class));
168+
}
169+
166170
public static Version readVersion(StreamInput in) throws IOException {
167171
return fromId(in.readVInt());
168172
}
@@ -412,10 +416,10 @@ public int compareTo(Version other) {
412416
public Version minimumCompatibilityVersion() {
413417
if (major >= 6) {
414418
// all major versions from 6 onwards are compatible with last minor series of the previous major
415-
final List<Version> declaredVersions = getDeclaredVersions(getClass());
416419
Version bwcVersion = null;
417-
for (int i = declaredVersions.size() - 1; i >= 0; i--) {
418-
final Version candidateVersion = declaredVersions.get(i);
420+
421+
for (int i = DeclaredVersionsHolder.DECLARED_VERSIONS.size() - 1; i >= 0; i--) {
422+
final Version candidateVersion = DeclaredVersionsHolder.DECLARED_VERSIONS.get(i);
419423
if (candidateVersion.major == major - 1 && candidateVersion.isRelease() && after(candidateVersion)) {
420424
if (bwcVersion != null && candidateVersion.minor < bwcVersion.minor) {
421425
break;

0 commit comments

Comments
 (0)