From 54e2a0e6944ac04a9fb4b4b3fe96281daeee93b4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 24 Aug 2020 17:01:04 -0700 Subject: [PATCH] Reland: Increase threshold for usage of compute for utf8 decoding on large strings to 50 KB (#64498) --- packages/flutter/lib/src/services/asset_bundle.dart | 8 +++++--- packages/flutter_tools/lib/src/run_hot.dart | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/services/asset_bundle.dart b/packages/flutter/lib/src/services/asset_bundle.dart index e9550a8b8a..1753fc6b83 100644 --- a/packages/flutter/lib/src/services/asset_bundle.dart +++ b/packages/flutter/lib/src/services/asset_bundle.dart @@ -71,11 +71,13 @@ abstract class AssetBundle { // that the null-handling logic is dead code). if (data == null) throw FlutterError('Unable to load asset: $key'); // ignore: dead_code - if (data.lengthInBytes < 10 * 1024) { - // 10KB takes about 3ms to parse on a Pixel 2 XL. - // See: https://github.com/dart-lang/sdk/issues/31954 + // 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.lengthInBytes < 50 * 1024) { 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"'); } diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 77a7867eab..a712bec06c 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -562,9 +562,11 @@ class HotRunner extends ResidentRunner { } on vm_service.RPCError { // Do nothing, we're already subcribed. } + // Ideally this would wait for kIsolateRunnable, but either this subscription occurs too + // late to receive the event, or it is not forwarded for hot restarted isolates. isolateNotifications.add( device.vmService.onIsolateEvent.firstWhere((vm_service.Event event) { - return event.kind == vm_service.EventKind.kIsolateRunnable; + return event.kind == vm_service.EventKind.kServiceExtensionAdded; }), ); }