Index: tracing/tracing/extras/importer/gzip_importer.html |
diff --git a/tracing/tracing/extras/importer/gzip_importer.html b/tracing/tracing/extras/importer/gzip_importer.html |
index a5dab95d3aa3e02ef9d8ddefeeebe8deaf6c046c..135d8f41b733c44a93879d9d04761900f82be27c 100644 |
--- a/tracing/tracing/extras/importer/gzip_importer.html |
+++ b/tracing/tracing/extras/importer/gzip_importer.html |
@@ -113,8 +113,34 @@ tr.exportTo('tr.e.importer', function() { |
// Inflate the data using jszip. |
var inflated_data = |
JSZip.compressions['DEFLATE'].uncompress(data.subarray(position)); |
- return JSZip.utils.transformTo('string', inflated_data); |
- }, |
+ return GzipImporter.transformToString_(inflated_data); |
+ }; |
+ |
+ /** |
+ * Transforms an array-like object to a string. |
+ * |
+ * Note that the following two expressions yield identical results: |
+ * |
+ * GzipImporter.transformToString_(data) |
+ * JSZip.utils.transformTo('string', data) |
+ * |
+ * We use a custom static method because it is faster and, more importantly, |
+ * avoids OOMing on large traces. See |
+ * https://github.com/catapult-project/catapult/issues/2051. |
+ */ |
+ GzipImporter.transformToString_ = function(data) { |
+ var type = JSZip.utils.getTypeOf(data); |
Sami
2016/02/25 14:44:54
Is it worth having a fallback to JSZip if TextDeco
petrcermak
2016/02/25 15:22:41
Done.
|
+ if (type === 'string') |
+ return data; // We already have a string. |
+ |
+ if (type === 'array') { |
+ // TextDecoder requires an ArrayBuffer or an ArrayBufferView. |
+ data = new Uint8Array(data); |
+ } |
+ |
+ var decoder = new TextDecoder('utf-8'); |
+ return decoder.decode(data); |
+ }; |
GzipImporter.prototype = { |
__proto__: tr.importer.Importer.prototype, |