Optimize memory usage of `RegularFileValue`... by removing it.
`RegularFileValue` (i.e. the path's real path is itself, and it's an existing file) is the common case situation for `FileValue`. In this situation we don't actually need to spend shallow heap to store a reference to the original `RootedPath` in order to service `FileValue#realRootedPath` and `FileValue#logicalChainDuringResolution`; instead we refactor all callers to pass in the original `RootedPath`. After making this change we notice that `RegularFileValue` is now just a wrapper around `FileStateValue`, so then we remove the need for the wrapper by turning `RegularFileValue` into an abstract class (an interface would also work), and then having `FileStateValue` extend it.
PiperOrigin-RevId: 655774211
Change-Id: Icf1684c85c605a267a85c7917bb53dffaeb85fd7
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index 0151bc0..6aec2b6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -386,21 +386,24 @@
}
} else {
// Stat the file.
+ RootedPath rootedPath = traversal.root().asRootedPath();
FileValue fileValue =
- (FileValue)
- env.getValueOrThrow(
- FileValue.key(traversal.root().asRootedPath()), IOException.class);
+ (FileValue) env.getValueOrThrow(FileValue.key(rootedPath), IOException.class);
if (env.valuesMissing()) {
return null;
}
- return toFileInfo(fileValue, env, traversal.root().asPath(), syscallCache);
+ return toFileInfo(rootedPath, fileValue, env, traversal.root().asPath(), syscallCache);
}
}
@Nullable
private static FileInfo toFileInfo(
- FileValue fileValue, Environment env, Path path, SyscallCache syscallCache)
+ RootedPath rootedPath,
+ FileValue fileValue,
+ Environment env,
+ Path path,
+ SyscallCache syscallCache)
throws IOException, InterruptedException {
if (fileValue.unboundedAncestorSymlinkExpansionChain() != null) {
SkyKey uniquenessKey =
@@ -437,7 +440,7 @@
return new FileInfo(
type,
withDigest(fileValue.realFileStateValue(), path, syscallCache),
- fileValue.realRootedPath(),
+ fileValue.realRootedPath(rootedPath),
unresolvedLinkTarget);
}
@@ -715,7 +718,12 @@
}
if (key instanceof FileValue.Key fileKey) {
FileInfo fileInfo =
- toFileInfo((FileValue) value, env, fileKey.argument().asPath(), syscallCache);
+ toFileInfo(
+ fileKey.argument(),
+ (FileValue) value,
+ env,
+ fileKey.argument().asPath(),
+ syscallCache);
if (fileInfo != null) {
childValues.add(resultForFileRoot(fileKey.argument(), fileInfo));
}