[framework] increase threshold for compute to 50Kb (#69307)

This commit is contained in:
Jonah Williams 2020-10-29 09:34:33 -07:00 committed by GitHub
parent 31c96b5d83
commit f68911ee1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,11 +71,13 @@ abstract class AssetBundle {
// that the null-handling logic is dead code). // that the null-handling logic is dead code).
if (data == null) if (data == null)
throw FlutterError('Unable to load asset: $key'); // ignore: dead_code throw FlutterError('Unable to load asset: $key'); // ignore: dead_code
if (data.lengthInBytes < 10 * 1024) { // 50 KB of data should take 2-3 ms to parse on a Moto G4, and about 400 μs
// 10KB takes about 3ms to parse on a Pixel 2 XL. // on a Pixel 4.
// See: https://github.com/dart-lang/sdk/issues/31954 if (data.lengthInBytes < 50 * 1024) {
return utf8.decode(data.buffer.asUint8List()); return utf8.decode(data.buffer.asUint8List());
} }
// For strings larger than 50 KB, run the computation in an isolate to
// avoid causing main thread jank.
return compute(_utf8decode, data, debugLabel: 'UTF8 decode for "$key"'); return compute(_utf8decode, data, debugLabel: 'UTF8 decode for "$key"');
} }