Java: cache class name for better inference performance

GitOrigin-RevId: 3f498927ef9124974bc2d3ad0574a9327da5ea51
This commit is contained in:
Bas Leijdekkers
2025-06-30 18:41:25 +00:00
committed by intellij-monorepo-bot
parent 565f7b3a1c
commit 8b4e7829cb
3 changed files with 230 additions and 31 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.source;
import com.intellij.codeInsight.TypeNullability;
@@ -38,6 +24,7 @@ public class PsiImmediateClassType extends PsiClassType.Stub {
private String myPresentableText;
private String myPresentableTextAnnotated;
private String myInternalCanonicalText;
private String myClassName;
private final ClassResolveResult myClassResolveResult = new ClassResolveResult() {
private ClassResolveResult myCapturedResult = null;
@@ -139,7 +126,11 @@ public class PsiImmediateClassType extends PsiClassType.Stub {
@Override
public String getClassName() {
return myClass.getName();
String className = myClassName;
if (className == null) {
myClassName = className = myClass.getName();
}
return className;
}
@Override
@@ -0,0 +1,218 @@
interface Map<K, V> {
@SafeVarargs
@SuppressWarnings("varargs")
static <K, V> Map<K, V> ofEntries(Entry<? extends K, ? extends V>... entries) {
return null;
}
static <K, V> Entry<K, V> entry(K k, V v) {
return null;
}
interface Entry<K, V> {}
}
class Performance {
private static final Map<String, String> translation = Map.ofEntries(
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg"),
Map.entry("a","b"),
Map.entry("c","b"),
Map.entry("d","b"),
Map.entry("e","f"),
Map.entry("g","gg")
);
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
@@ -31,6 +17,10 @@ import org.jetbrains.annotations.NonNls;
public class InferencePerformanceTest extends LightDaemonAnalyzerTestCase {
@NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/performance";
public void testGenericMethodCallPassedToVarargs() {
Benchmark.newBenchmark("200 generic method calls passed to Map.entry", this::doTest).start();
}
public void testPolyMethodCallArgumentPassedToVarargs() {
Benchmark.newBenchmark("50 poly method calls passed to Arrays.asList", this::doTest).start();
}