Skip to content

Commit

Permalink
fix: compute must receive static method
Browse files Browse the repository at this point in the history
  • Loading branch information
wssgcg1213 committed Mar 23, 2022
1 parent 2573e77 commit d98a8fb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions kraken/lib/src/launcher/bundle.dart
Expand Up @@ -231,19 +231,21 @@ class NetworkBundle extends KrakenBundle {
}
}

Future<String> _resolveStringFromData(List<int> data, { Codec codec = utf8 }) async {
Future<String> _resolveStringFromData(final List<int> data) async {
// Utf8 decode is fast enough with dart 2.10
// reference: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/asset_bundle.dart#L71
// 50 KB of data should take 2-3 ms to parse on a Moto G4, and about 400 μs
// on a Pixel 4.
if (data.length < 50 * 1024) {
return codec.decode(data);
return utf8.decode(data);
}
// For strings larger than 50 KB, run the computation in an isolate to
// avoid causing main thread jank.
return compute((data) => codec.decode(data), data);
return compute(_utf8decode, data);
}

String _utf8decode(List<int> data) => utf8.decode(data);

class AssetsBundle extends KrakenBundle {
AssetsBundle(String url) : super(url);

Expand Down

0 comments on commit d98a8fb

Please sign in to comment.