Skip to content

Commit ac16d2c

Browse files
jonathanpeppersjonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] leave classes.zip uncompressed (#2140)
I was thinking about a couple of the slower MSBuild tasks: - `Javac` - `CompileToDalvik` One thing I noticed here was that `Javac` outputs a `classes.zip` file, and `CompileToDalvik` consumes it. It also looked like we are using `CompressionMethod.Default` as you would expect. So why should we compress this file at all? It seemed that was work we could just skip and things would work fine? Presumably `dx.jar` can work with an uncompressed `classes.zip` file faster than a compressed one? So I made the following changes: - Added an option to pass in the `CompressionMethod` in `ZipArchiveEx` - Used `CompressionMethod.Store` for creating `classes.zip` The results on a File | New Xamarin.Forms app looked great! Before: 3443 ms Javac 1 calls 11545 ms CompileToDalvik 1 calls After: 3338 ms Javac 1 calls 10535 ms CompileToDalvik 1 calls I did a `Clean` before running the `SignAndroidPackage` target on these builds. These savings seem pretty good! The only drawback being we use more disk space in `$(IntermediateOutputPath)`.
1 parent d8e9a30 commit ac16d2c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Build.Utilities;
88
using System.Text;
99
using System.Collections.Generic;
10+
using Xamarin.Tools.Zip;
1011

1112
namespace Xamarin.Android.Tasks
1213
{
@@ -36,7 +37,7 @@ public override bool Execute ()
3637
return result;
3738
// compress all the class files
3839
using (var zip = new ZipArchiveEx (Path.Combine (ClassesOutputDirectory, "..", "classes.zip"), FileMode.OpenOrCreate))
39-
zip.AddDirectory (ClassesOutputDirectory, "");
40+
zip.AddDirectory (ClassesOutputDirectory, "", CompressionMethod.Store);
4041
return result;
4142
}
4243

src/Xamarin.Android.Build.Tasks/Utilities/ZipArchiveEx.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ string ArchiveNameForFile (string filename, string directoryPathInZip)
5252
return pathName.Replace ("\\", "/");
5353
}
5454

55-
void AddFiles (string folder, string folderInArchive)
55+
void AddFiles (string folder, string folderInArchive, CompressionMethod method)
5656
{
5757
int count = 0;
5858
foreach (string fileName in Directory.GetFiles (folder, "*.*", SearchOption.TopDirectoryOnly)) {
@@ -64,9 +64,9 @@ void AddFiles (string folder, string folderInArchive)
6464
if (zip.ContainsEntry (archiveFileName, out index)) {
6565
var e = zip.First (x => x.FullName == archiveFileName);
6666
if (e.ModificationTime < fi.LastWriteTimeUtc)
67-
zip.AddFile (fileName, archiveFileName);
67+
zip.AddFile (fileName, archiveFileName, compressionMethod: method);
6868
} else {
69-
zip.AddFile (fileName, archiveFileName);
69+
zip.AddFile (fileName, archiveFileName, compressionMethod: method);
7070
}
7171
count++;
7272
if (count == ZipArchiveEx.ZipFlushLimit) {
@@ -84,7 +84,7 @@ public void RemoveFile (string folder, string file)
8484
zip.DeleteEntry ((ulong)index);
8585
}
8686

87-
public void AddDirectory (string folder, string folderInArchive)
87+
public void AddDirectory (string folder, string folderInArchive, CompressionMethod method = CompressionMethod.Default)
8888
{
8989
if (!string.IsNullOrEmpty (folder)) {
9090
folder = folder.Replace ('/', Path.DirectorySeparatorChar).Replace ('\\', Path.DirectorySeparatorChar);
@@ -94,7 +94,7 @@ public void AddDirectory (string folder, string folderInArchive)
9494
}
9595
}
9696

97-
AddFiles (folder, folderInArchive);
97+
AddFiles (folder, folderInArchive, method);
9898
foreach (string dir in Directory.GetDirectories (folder, "*", SearchOption.AllDirectories)) {
9999
var di = new DirectoryInfo (dir);
100100
if ((di.Attributes & FileAttributes.Hidden) != 0)
@@ -106,7 +106,7 @@ public void AddDirectory (string folder, string folderInArchive)
106106
} catch (ZipException) {
107107

108108
}
109-
AddFiles (dir, fullDirPath);
109+
AddFiles (dir, fullDirPath, method);
110110
}
111111
}
112112

0 commit comments

Comments
 (0)