diff options
author | kmb <kmb@google.com> | 2017-10-31 17:49:07 -0400 |
---|---|---|
committer | John Cater <jcater@google.com> | 2017-11-01 09:58:57 -0400 |
commit | 85a32d2451526a83ebfdff2a0345006f678b8170 (patch) | |
tree | 0ac40317845dc8cb2512f30a88e2ce8873401513 /src/tools/android/java/com/google/devtools/build/android/ziputils | |
parent | 2ad8c6978f786795b501dd4e6fa6b94cd910a485 (diff) |
Force DexMapper (aka shuffle_jars) tool to partition large packages into multiple shards. Also fix some weirdnesses with how shard assignments were recorded.
RELNOTES: None.
PiperOrigin-RevId: 174095450
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/ziputils')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java b/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java index cc5640df92..dab87efc65 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java +++ b/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java @@ -26,7 +26,7 @@ class Splitter { private final Map<String, Integer> assigned; private int size = 0; private int shard = 0; - private String currPath = null; + private String prevPath = null; private int remaining; private int idealSize; private int almostFull; @@ -85,7 +85,7 @@ class Splitter { // Before you change this, please do the math. // It's not always perfect, but designed to keep shards reasonably balanced in most cases. int limit = Math.min(Math.min(10, (idealSize + 3) / 4), (int) Math.log(numberOfShards)); - almostFull = idealSize - limit; + almostFull = idealSize - limit; } /** @@ -102,7 +102,7 @@ class Splitter { // last shard, no choice if (shard == numberOfShards - 1) { size++; - assigned.put(currPath, shard); + assigned.put(path, shard); return shard; } @@ -112,23 +112,26 @@ class Splitter { nextShard(); } size++; - assigned.put(currPath, shard); + assigned.put(path, shard); return shard; } - String prevPath = currPath; - currPath = path; - // If current shard is at least "almost full", check for package boundary? - if (prevPath != null && size >= almostFull) { - int i = currPath.lastIndexOf(ARCHIVE_FILE_SEPARATOR); - String dir = i > 0 ? currPath.substring(0, i) : "."; + // If current shard is "over-full", forcibly roll over. Otherwise, if current shard is + // "almost full", check for package boundary. The forced rollover is in particular important + // when all or almost all classes are in the default package, as Proguard likes to make it. + if (size >= (idealSize + (idealSize - almostFull))) { + nextShard(); + } else if (prevPath != null && size >= almostFull) { + int i = path.lastIndexOf(ARCHIVE_FILE_SEPARATOR); + String dir = i > 0 ? path.substring(0, i) : "."; i = prevPath.lastIndexOf(ARCHIVE_FILE_SEPARATOR); String prevDir = i > 0 ? prevPath.substring(0, i) : "."; if (!dir.equals(prevDir)) { nextShard(); } } - assigned.put(currPath, shard); + prevPath = path; + assigned.put(path, shard); size++; return shard; } |