summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-15 14:17:47 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-15 14:17:51 -0800
commitd9cfdd877cb4d09e7be414d30643aac38430101d (patch)
tree4370f2e196feea61143281d2dcb4bcdf2843f661 /core
parent28c099486199c8fbf1c1f5247278a0484e8a747b (diff)
downloadmill-d9cfdd877cb4d09e7be414d30643aac38430101d.tar.gz
mill-d9cfdd877cb4d09e7be414d30643aac38430101d.tar.bz2
mill-d9cfdd877cb4d09e7be414d30643aac38430101d.zip
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
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/mill/eval/PathRef.scala30
1 files changed, 20 insertions, 10 deletions
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{