Skip to content
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

Optimize VisitorState#getSymbolFromName #3504

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions check_api/src/main/java/com/google/errorprone/VisitorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
import com.sun.tools.javac.code.Type.ArrayType;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.comp.Modules;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.parser.Tokens.Token;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Convert;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Options;
Expand Down Expand Up @@ -406,20 +406,8 @@ public Name binaryNameFromClassname(String className) {
*/
@Nullable
public ClassSymbol getSymbolFromName(Name name) {
boolean modular = sharedState.modules.getDefaultModule() != getSymtab().noModule;
if (!modular) {
return getSymbolFromString(getSymtab().noModule, name);
}
for (ModuleSymbol msym : sharedState.modules.allModules()) {
ClassSymbol result = getSymbolFromString(msym, name);
if (result != null) {
// TODO(cushon): the path where we iterate over all modules is probably slow.
// Try to learn some lessons from JDK-8189747, and consider disallowing this case and
// requiring users to call the getSymbolFromString(ModuleSymbol, Name) overload instead.
return result;
}
}
return null;
ModuleSymbol msym = getSymtab().inferModule(Convert.packagePart(name));
return msym != null ? getSymbolFromString(msym, name) : null;
Comment on lines +409 to +410
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Symtab#inferModule performs a map lookup rather than a linear scan. This approach is derived from this JDK logic. With it, the build still passes, as does the Error Prone Support build. That said, neither uses custom modularization, so I can't fully rule out that this logic behaves subtly different.

}

@Nullable
Expand Down Expand Up @@ -735,7 +723,6 @@ public static <T> Supplier<T> memoize(Supplier<T> f) {
* {@code SomeClass.instance(context)} has sizable performance improvements in aggregate.
*/
private static final class SharedState {
private final Modules modules;
private final Names names;
private final Symtab symtab;
private final ErrorProneTimings timings;
Expand All @@ -759,7 +746,6 @@ private static final class SharedState {
StatisticsCollector statisticsCollector,
Map<String, SeverityLevel> severityMap,
ErrorProneOptions errorProneOptions) {
this.modules = Modules.instance(context);
this.names = Names.instance(context);
this.symtab = Symtab.instance(context);
this.timings = ErrorProneTimings.instance(context);
Expand Down