From d9cfdd877cb4d09e7be414d30643aac38430101d Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 15 Nov 2017 14:17:47 -0800 Subject: Allow opting in to faster/sloppier `PathRef` signatures using mtime + filesize instead of md5ing the file body. Used for third-party dependencies (which are large jars but shouldn't change often) this speeds up the no-op `mill run ScalaPlugin.compile` by about a quarter --- core/src/main/scala/mill/eval/PathRef.scala | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'core') diff --git a/core/src/main/scala/mill/eval/PathRef.scala b/core/src/main/scala/mill/eval/PathRef.scala index fa373b5a..5d96d8df 100644 --- a/core/src/main/scala/mill/eval/PathRef.scala +++ b/core/src/main/scala/mill/eval/PathRef.scala @@ -15,8 +15,8 @@ import mill.util.JsonFormatters * on the contents of the filesystem underneath it. Used to ensure filesystem * changes can bust caches which are keyed off hashcodes. */ -case class PathRef(path: ammonite.ops.Path){ - val md5Hash = { +case class PathRef(path: ammonite.ops.Path, quick: Boolean = false){ + val sig = { val digest = MessageDigest.getInstance("MD5") val buffer = new Array[Byte](16 * 1024) @@ -30,15 +30,25 @@ case class PathRef(path: ammonite.ops.Path){ def visitFile(file: jnio.Path, attrs: BasicFileAttributes) = { digest.update(file.toAbsolutePath.toString.getBytes) - val is = jnio.Files.newInputStream(file) - def rec(): Unit = { - val length = is.read(buffer) - if (length != -1){ - digest.update(buffer, 0, length) - rec() + if (quick){ + val value = (path.mtime.toMillis, path.size).hashCode() + digest.update((value >>> 24).toByte) + digest.update((value >>> 16).toByte) + digest.update((value >>> 8).toByte) + digest.update(value.toByte) + }else { + println("Hashing " + file) + val is = jnio.Files.newInputStream(file) + + def rec(): Unit = { + val length = is.read(buffer) + if (length != -1) { + digest.update(buffer, 0, length) + rec() + } } + rec() } - rec() FileVisitResult.CONTINUE } @@ -50,7 +60,7 @@ case class PathRef(path: ammonite.ops.Path){ java.util.Arrays.hashCode(digest.digest()) } - override def hashCode() = md5Hash + override def hashCode() = sig } object PathRef{ -- cgit v1.2.3