From 9dc32111d5b6c1c7c5eaf39efad5fef75327ee75 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 May 2016 14:05:14 +0000 Subject: Remove unnecessary sorting from CppCompileAction.computeKey(). This showed up as a hotspot (3% of CPU time) in profiles of large C++ builds. -- MOS_MIGRATED_REVID=121943041 --- .../build/lib/rules/cpp/CppCompileAction.java | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'src/main/java/com/google/devtools') diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java index e40ddc8843..721ad0f889 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java @@ -1093,19 +1093,6 @@ public class CppCompileAction extends AbstractAction return context.getDeclaredIncludeSrcs(); } - /** - * Return explicit header files (i.e., header files explicitly listed) in an order - * that is stable between builds. - */ - protected final List getDeclaredIncludeSrcsInStableOrder() { - List paths = new ArrayList<>(); - for (Artifact declaredIncludeSrc : context.getDeclaredIncludeSrcs()) { - paths.add(declaredIncludeSrc.getExecPath()); - } - Collections.sort(paths); // Order is not important, but stability is. - return paths; - } - @Override public ResourceSet estimateResourceConsumption(Executor executor) { return executor.getContext(actionContext).estimateResourceConsumption(this); @@ -1142,8 +1129,13 @@ public class CppCompileAction extends AbstractAction */ f.addPaths(context.getDeclaredIncludeDirs()); f.addPaths(context.getDeclaredIncludeWarnDirs()); - f.addPaths(getDeclaredIncludeSrcsInStableOrder()); - f.addPaths(Artifact.asSortedPathFragments(getMandatoryInputs())); + for (Artifact declaredIncludeSrc : context.getDeclaredIncludeSrcs()) { + f.addPath(declaredIncludeSrc.getExecPath()); + } + f.addInt(0); // mark the boundary between input types + for (Artifact input : getMandatoryInputs()) { + f.addPath(input.getExecPath()); + } return f.hexDigestAndReset(); } @@ -1252,9 +1244,9 @@ public class CppCompileAction extends AbstractAction message.append('\n'); } - for (PathFragment path : getDeclaredIncludeSrcsInStableOrder()) { + for (Artifact src : getDeclaredIncludeSrcs()) { message.append(" Declared include source: "); - message.append(ShellEscaper.escapeString(path.getPathString())); + message.append(ShellEscaper.escapeString(src.getExecPathString())); message.append('\n'); } -- cgit v1.2.3