Automated rollback of commit e2385a5ebd484f63d85851a6f5300b15016d9f2b.
*** Reason for rollback ***
Breaks Kythe
*** Original change description ***
Open and read bzl files at most once per build.
Currently Bazel is opening and reading bzl files twice: once to get their contents, and once to get their digest. Instead we can simply grab the precomputed digest from the FileValue we already have, or we can compute it on the fly from the contents we just read. Therefore, this CL is a [small] strict performance win.
RELNOTES: None
PiperOrigin-RevId: 307824662
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
index 51ab1e8..957bcee 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
@@ -26,7 +26,6 @@
import com.google.devtools.build.lib.syntax.StarlarkFile;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.lib.syntax.ValidationEnvironment;
-import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Root;
@@ -130,9 +129,8 @@
fileValue.isSpecialFile()
? FileSystemUtils.readContent(path)
: FileSystemUtils.readWithKnownFileSize(path, fileValue.getSize());
- byte[] digest = getDigestFromFileValueOrFromKnownFileContents(fileValue, bytes);
ParserInput input = ParserInput.create(bytes, path.toString());
- file = StarlarkFile.parseWithDigest(input, digest, options);
+ file = StarlarkFile.parseWithDigest(input, path.getDigest(), options);
} catch (IOException e) {
throw new ErrorReadingSkylarkExtensionException(e, Transience.TRANSIENT);
}
@@ -145,15 +143,6 @@
return ASTFileLookupValue.withFile(file);
}
- private static byte[] getDigestFromFileValueOrFromKnownFileContents(
- FileValue fileValue, byte[] contents) {
- byte[] digest = fileValue.getDigest();
- if (digest != null) {
- return digest;
- }
- return DigestHashFunction.getDefaultUnchecked().getHashFunction().hashBytes(contents).asBytes();
- }
-
@Nullable
@Override
public String extractTag(SkyKey skyKey) {