Skip to content

Commit 9dc3211

Browse files
Googleraehlig
authored andcommitted
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
1 parent aae3e40 commit 9dc3211

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,19 +1093,6 @@ public NestedSet<Artifact> getDeclaredIncludeSrcs() {
10931093
return context.getDeclaredIncludeSrcs();
10941094
}
10951095

1096-
/**
1097-
* Return explicit header files (i.e., header files explicitly listed) in an order
1098-
* that is stable between builds.
1099-
*/
1100-
protected final List<PathFragment> getDeclaredIncludeSrcsInStableOrder() {
1101-
List<PathFragment> paths = new ArrayList<>();
1102-
for (Artifact declaredIncludeSrc : context.getDeclaredIncludeSrcs()) {
1103-
paths.add(declaredIncludeSrc.getExecPath());
1104-
}
1105-
Collections.sort(paths); // Order is not important, but stability is.
1106-
return paths;
1107-
}
1108-
11091096
@Override
11101097
public ResourceSet estimateResourceConsumption(Executor executor) {
11111098
return executor.getContext(actionContext).estimateResourceConsumption(this);
@@ -1142,8 +1129,13 @@ public String computeKey() {
11421129
*/
11431130
f.addPaths(context.getDeclaredIncludeDirs());
11441131
f.addPaths(context.getDeclaredIncludeWarnDirs());
1145-
f.addPaths(getDeclaredIncludeSrcsInStableOrder());
1146-
f.addPaths(Artifact.asSortedPathFragments(getMandatoryInputs()));
1132+
for (Artifact declaredIncludeSrc : context.getDeclaredIncludeSrcs()) {
1133+
f.addPath(declaredIncludeSrc.getExecPath());
1134+
}
1135+
f.addInt(0); // mark the boundary between input types
1136+
for (Artifact input : getMandatoryInputs()) {
1137+
f.addPath(input.getExecPath());
1138+
}
11471139
return f.hexDigestAndReset();
11481140
}
11491141

@@ -1252,9 +1244,9 @@ public String describeKey() {
12521244
message.append('\n');
12531245
}
12541246

1255-
for (PathFragment path : getDeclaredIncludeSrcsInStableOrder()) {
1247+
for (Artifact src : getDeclaredIncludeSrcs()) {
12561248
message.append(" Declared include source: ");
1257-
message.append(ShellEscaper.escapeString(path.getPathString()));
1249+
message.append(ShellEscaper.escapeString(src.getExecPathString()));
12581250
message.append('\n');
12591251
}
12601252

0 commit comments

Comments
 (0)