From 68514d455cac2998d800979b3310d5b89d2b800e Mon Sep 17 00:00:00 2001 From: Stephan Herrmann Date: Tue, 3 Dec 2024 18:44:09 +0100 Subject: [PATCH] [Performance] Full build takes more time since 2024-09 (type inference) (#3384) optimize 3: + never visit the same super type more than once Fixes https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3327 --- .../eclipse/jdt/internal/compiler/lookup/BoundSet.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java index 871f9fe03db..360a4ea4408 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java @@ -1264,8 +1264,14 @@ private boolean superOnlyRaw(TypeBinding g, TypeBinding s, LookupEnvironment env } protected List> allSuperPairsWithCommonGenericType(TypeBinding s, TypeBinding t) { + return allSuperPairsWithCommonGenericTypeRecursive(s, t, new HashSet<>()); + } + + private List> allSuperPairsWithCommonGenericTypeRecursive(TypeBinding s, TypeBinding t, HashSet visited) { if (s == null || s.id == TypeIds.T_JavaLangObject || t == null || t.id == TypeIds.T_JavaLangObject) return Collections.emptyList(); + if (!visited.add(s.prototype())) + return Collections.emptyList(); List> result = new ArrayList<>(); if (s.isParameterizedType() && t.isParameterizedType() // optimization #1: clients of this method only want to compare type arguments && TypeBinding.equalsEquals(s.original(), t.original())) { @@ -1277,11 +1283,11 @@ protected List> allSuperPairsWithCommonGenericType(TypeBinding if (tSuper != null && s.isParameterizedType() && tSuper.isParameterizedType()) { // optimization #1 again result.add(new Pair<>(s, tSuper)); } - result.addAll(allSuperPairsWithCommonGenericType(s.superclass(), t)); + result.addAll(allSuperPairsWithCommonGenericTypeRecursive(s.superclass(), t, visited)); ReferenceBinding[] superInterfaces = s.superInterfaces(); if (superInterfaces != null) { for (ReferenceBinding superInterface : superInterfaces) { - result.addAll(allSuperPairsWithCommonGenericType(superInterface, t)); + result.addAll(allSuperPairsWithCommonGenericTypeRecursive(superInterface, t, visited)); } } return result;