A few FilesystemValueChecker improvements.
- Pass possibly-modified keys around as a Collection rather than an Iterable.
- Remove an atomic that counted the possibly-modified keys.
- Use a lambda in getDiff.
Closes #10585.
PiperOrigin-RevId: 299310888
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/FilesystemValueChecker.java b/src/main/java/com/google/devtools/build/lib/skyframe/FilesystemValueChecker.java
index 44665ee..75d5ee2 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/FilesystemValueChecker.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/FilesystemValueChecker.java
@@ -113,7 +113,7 @@
*/
public ImmutableBatchDirtyResult getNewAndOldValues(
Map<SkyKey, SkyValue> valuesMap,
- Iterable<SkyKey> keys,
+ Collection<SkyKey> keys,
SkyValueDirtinessChecker dirtinessChecker)
throws InterruptedException {
return getDirtyValues(new MapBackedValueFetcher(valuesMap), keys,
@@ -124,9 +124,11 @@
* Returns a {@link Differencer.DiffWithDelta} containing keys that are dirty according to the
* passed-in {@code dirtinessChecker}.
*/
- public Differencer.DiffWithDelta getNewAndOldValues(WalkableGraph walkableGraph,
- Iterable<SkyKey> keys, SkyValueDirtinessChecker dirtinessChecker)
- throws InterruptedException {
+ public Differencer.DiffWithDelta getNewAndOldValues(
+ WalkableGraph walkableGraph,
+ Collection<SkyKey> keys,
+ SkyValueDirtinessChecker dirtinessChecker)
+ throws InterruptedException {
return getDirtyValues(new WalkableGraphBackedValueFetcher(walkableGraph), keys,
dirtinessChecker, /*checkMissingValues=*/true);
}
@@ -484,7 +486,7 @@
private ImmutableBatchDirtyResult getDirtyValues(
ValueFetcher fetcher,
- Iterable<SkyKey> keys,
+ Collection<SkyKey> keys,
final SkyValueDirtinessChecker checker,
final boolean checkMissingValues)
throws InterruptedException {
@@ -495,7 +497,6 @@
ThrowableRecordingRunnableWrapper wrapper =
new ThrowableRecordingRunnableWrapper("FilesystemValueChecker#getDirtyValues");
- final AtomicInteger numKeysScanned = new AtomicInteger(0);
final AtomicInteger numKeysChecked = new AtomicInteger(0);
MutableBatchDirtyResult batchResult = new MutableBatchDirtyResult(numKeysChecked);
ElapsedTimeReceiver elapsedTimeReceiver =
@@ -506,12 +507,11 @@
"Spent %d ms checking %d filesystem nodes (%d scanned)",
TimeUnit.MILLISECONDS.convert(elapsedTimeNanos, TimeUnit.NANOSECONDS),
numKeysChecked.get(),
- numKeysScanned.get()));
+ keys.size()));
}
};
try (AutoProfiler prof = AutoProfiler.create(elapsedTimeReceiver)) {
for (final SkyKey key : keys) {
- numKeysScanned.incrementAndGet();
if (!checker.applies(key)) {
continue;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index 4d60e42..9c37cf0 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -16,7 +16,6 @@
import static com.google.devtools.build.lib.concurrent.Uninterruptibles.callUninterruptibly;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
@@ -1265,23 +1264,20 @@
protected Differencer.Diff getDiff(
TimestampGranularityMonitor tsgm,
- Iterable<PathFragment> modifiedSourceFiles,
+ Collection<PathFragment> modifiedSourceFiles,
final Root pathEntry)
throws InterruptedException {
- if (Iterables.isEmpty(modifiedSourceFiles)) {
+ if (modifiedSourceFiles.isEmpty()) {
return new ImmutableDiff(ImmutableList.<SkyKey>of(), ImmutableMap.<SkyKey, SkyValue>of());
}
// TODO(bazel-team): change ModifiedFileSet to work with RootedPaths instead of PathFragments.
- Iterable<SkyKey> dirtyFileStateSkyKeys =
- Iterables.transform(
+ Collection<SkyKey> dirtyFileStateSkyKeys =
+ Collections2.transform(
modifiedSourceFiles,
- new Function<PathFragment, SkyKey>() {
- @Override
- public SkyKey apply(PathFragment pathFragment) {
- Preconditions.checkState(
- !pathFragment.isAbsolute(), "found absolute PathFragment: %s", pathFragment);
- return FileStateValue.key(RootedPath.toRootedPath(pathEntry, pathFragment));
- }
+ pathFragment -> {
+ Preconditions.checkState(
+ !pathFragment.isAbsolute(), "found absolute PathFragment: %s", pathFragment);
+ return FileStateValue.key(RootedPath.toRootedPath(pathEntry, pathFragment));
});
// We only need to invalidate directory values when a file has been created or deleted or
// changes type, not when it has merely been modified. Unfortunately we do not have that