We use ICSharpCode.SharpZipLib.dll to do unzip and find the same piece of code is about 7~8 times slower when built with il2cpp than mono2.x. the unity version is 4.6.6p1.
code clip:
System.IO.MemoryStream inStream = new System.IO.MemoryStream(paramDict["DownloadedBytes"] as byte[]);
ZipInputStream zipInputStream = new ZipInputStream(inStream);
System.IO.BinaryReader br = new System.IO.BinaryReader(zipInputStream);
zipInputStream.IsStreamOwner = true;
if (System.IO.File.Exists(assetBundlePath)) System.IO.File.Delete(assetBundlePath);
System.IO.FileStream outStream = System.IO.File.OpenWrite(assetBundlePath);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(outStream);
ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
ZipEntry zipEntry;
bool outputOK = true;
timeBuilder.Append("OpenFile:");
timeBuilder.Append((DateTime.Now - startTime).TotalMilliseconds);
try
{
zipEntry = zipInputStream.GetNextEntry();
}
catch (System.Exception err)
{
zipEntry = null;
SuperDebug.Log(SuperDebug.ASSETBUNDLE, "Unzip failed. " + err.Message);
}
if (zipEntry != null)
{
byte[] buff;
int chunk_size = 4096;
double readTime = 0;
double writeTime = 0;
double updateCrcTime = 0;
DateTime tempStartTime;
timeBuilder.Append("BeforeReadFirstChunk:");
timeBuilder.Append((DateTime.Now - startTime).TotalMilliseconds);
try
{
tempStartTime = DateTime.Now;
buff = br.ReadBytes(chunk_size);
readTime += (DateTime.Now - tempStartTime).TotalMilliseconds;
}
catch (System.Exception err)
{
buff = null;
zipEntry = null;
SuperDebug.Log(SuperDebug.ASSETBUNDLE, "Unzip failed." + err.Message);
}
timeBuilder.Append("BeforeWriteFile:");
timeBuilder.Append((DateTime.Now - startTime).TotalMilliseconds);
while (buff != null && buff.Length > 0)
{
try
{
tempStartTime = DateTime.Now;
bw.Write(buff);
writeTime += (DateTime.Now - tempStartTime).TotalMilliseconds;
}
catch (System.Exception err)
{
outputOK = false;
SuperDebug.Log(SuperDebug.ASSETBUNDLE, "Write cache failed. " + err.Message);
break;
}
tempStartTime = DateTime.Now;
crc.Update(buff);
updateCrcTime += (DateTime.Now - tempStartTime).TotalMilliseconds;
try
{
tempStartTime = DateTime.Now;
buff = br.ReadBytes(chunk_size);
readTime += (DateTime.Now - tempStartTime).TotalMilliseconds;
}
catch (System.Exception err)
{
buff = null;
zipEntry = null;
SuperDebug.Log(SuperDebug.ASSETBUNDLE, "Unzip failed." + err.Message);
}
}
timeBuilder.Append("AfterWriteFile:");
timeBuilder.Append((DateTime.Now - startTime).TotalMilliseconds);
timeBuilder.Append("WriteDetail:"+readTime+","+writeTime+","+updateCrcTime);
}
outStream.Close();
zipInputStream.Close();
SuperDebug.Log(SuperDebug.ASSETBUNDLE, "WriteCacheTime: " + timeBuilder.ToString());
↧