Skip to content

Commit 74dcf3b

Browse files
Wyveraldcopybara-github
authored andcommitted
Add some profiling spans for slow null builds with Skycache
- `initAnalysisCacheClient`: Creating the `analysisCacheClient` the first time in each invocation is slow because we re-establish the RPC connection (accounts for ~1.1s). This isn't super straightforward to fix, but at least adding a profile span here will cover a thus far "unexplained" timespan. - `getDeserializedKeys`: This is the part where we dig up all SkyKeys that were deserialized instead of directly evaluated, and invalidate them. Compared to `initAnalysisCacheClient` above, this is usually not very big. - Also applied a minor optimization here: `getDoneValues()` produces a filtered view of the `InMemoryGraph`, which we then filtered further using `parallelStream()`. We could just filter once by directly calling `getAllNodeEntries()` instead. PiperOrigin-RevId: 882580327 Change-Id: Ia4e2282a9158d5c66801d942ffba58128e6387ac
1 parent 5b86904 commit 74dcf3b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@
314314
import java.util.LinkedHashMap;
315315
import java.util.List;
316316
import java.util.Map;
317-
import java.util.Map.Entry;
318317
import java.util.Optional;
319318
import java.util.Set;
320319
import java.util.TreeSet;
@@ -612,11 +611,14 @@ public void invalidateWithExternalService(ExtendedEventHandler eventHandler)
612611
return;
613612
}
614613

615-
ImmutableSet<SkyKey> keysToLookup =
616-
getEvaluator().getDoneValues().entrySet().parallelStream()
617-
.filter(e -> e.getValue() instanceof DeserializedSkyValue)
618-
.map(Entry::getKey)
619-
.collect(toImmutableSet());
614+
ImmutableSet<SkyKey> keysToLookup;
615+
try (SilentCloseable c = Profiler.instance().profile("getDeserializedKeys")) {
616+
keysToLookup =
617+
getEvaluator().getInMemoryGraph().getAllNodeEntries().parallelStream()
618+
.filter(e -> e.isDone() && e.getValue() instanceof DeserializedSkyValue)
619+
.map(InMemoryNodeEntry::getKey)
620+
.collect(toImmutableSet());
621+
}
620622

621623
if (!remoteAnalysisCachingCurrentlyEnabled) {
622624
// If skycache is currently disabled, we need to delete all the deserialized nodes

src/main/java/com/google/devtools/build/lib/skyframe/serialization/analysis/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ java_library(
384384
"//src/main/java/com/google/devtools/build/lib/events",
385385
"//src/main/java/com/google/devtools/build/lib/packages",
386386
"//src/main/java/com/google/devtools/build/lib/pkgcache:package_path_codec_dependencies",
387+
"//src/main/java/com/google/devtools/build/lib/profiler",
387388
"//src/main/java/com/google/devtools/build/lib/runtime:blaze_command_cluster",
388389
"//src/main/java/com/google/devtools/build/lib/runtime:instrumentation_output",
389390
"//src/main/java/com/google/devtools/build/lib/skyframe:prerequisite_package_function",

src/main/java/com/google/devtools/build/lib/skyframe/serialization/analysis/RemoteAnalysisCacheManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import com.google.devtools.build.lib.events.ExtendedEventHandler;
4848
import com.google.devtools.build.lib.packages.RuleClassProvider;
4949
import com.google.devtools.build.lib.pkgcache.PackagePathCodecDependencies;
50+
import com.google.devtools.build.lib.profiler.Profiler;
51+
import com.google.devtools.build.lib.profiler.SilentCloseable;
5052
import com.google.devtools.build.lib.runtime.CommandEnvironment;
5153
import com.google.devtools.build.lib.runtime.InstrumentationOutput;
5254
import com.google.devtools.build.lib.runtime.InstrumentationOutputFactory.DestinationRelativeTo;
@@ -265,7 +267,11 @@ public static AnalysisDeps forAnalysis(
265267
case RemoteAnalysisCacheMode.DUMP_UPLOAD_MANIFEST_ONLY, RemoteAnalysisCacheMode.UPLOAD ->
266268
new AnalysisDeps(manager, deps, deps);
267269
case RemoteAnalysisCacheMode.DOWNLOAD -> {
268-
if (deps.getAnalysisCacheClient() == null) {
270+
RemoteAnalysisCacheClient analysisCacheClient;
271+
try (SilentCloseable unused = Profiler.instance().profile("initAnalysisCacheClient")) {
272+
analysisCacheClient = deps.getAnalysisCacheClient();
273+
}
274+
if (analysisCacheClient == null) {
269275
if (Strings.isNullOrEmpty(options.analysisCacheService)) {
270276
env.getReporter()
271277
.handle(
@@ -278,7 +284,7 @@ public static AnalysisDeps forAnalysis(
278284
.handle(
279285
Event.warn(
280286
"Failed to establish connection to AnalysisCacheService. Falling back to"
281-
+ " on local evaluation."));
287+
+ " local evaluation."));
282288
}
283289
yield new AnalysisDeps(
284290
DisabledDependenciesProvider.INSTANCE,

0 commit comments

Comments
 (0)