Skip to content

iOS: Dart_TimelineEvent is surprisingly slow #47850

@gaaclarke

Description

@gaaclarke

This tracker is for issues related to:

  • Dart VM

Description

I was doing some performance testing on iOS and noticed that 7% of CPU time was spent in GetCurrentThreadCPUMicrosForTimeline. It is the second hottest symbol I'm executing beyond memcpy (I'm copying thousands of buffers that are a megabyte big for microbenchmarks). Compared to the other symbols, some that are also doing system calls, it's shocking how much CPU time it is taking.

Screen Shot 2021-12-03 at 3 36 44 PM

Steps to reproduce

  1. Check out https://github.com/flutter/flutter/tree/master/dev/benchmarks/platform_channels_benchmarks
  2. Make the following code change so channels use compute (which will call Dart_TimelineEvent which calls GetCurrentThreadCPUMicrosForTimeline)\
--- a/packages/flutter/lib/src/services/platform_channel.dart
+++ b/packages/flutter/lib/src/services/platform_channel.dart
@@ -57,7 +57,10 @@ class BasicMessageChannel<T> {
   /// Returns a [Future] which completes to the received response, which may
   /// be null.
   Future<T?> send(T message) async {
-    return codec.decodeMessage(await binaryMessenger.send(name, codec.encodeMessage(message)));
+    final ByteData? encodedResult =
+      await binaryMessenger.send(name, codec.encodeMessage(message));
+    return compute<ByteData?, T?>(codec.decodeMessage, encodedResult);    
+//    return codec.decodeMessage(await binaryMessenger.send(name, codec.encodeMessage(message)));
   }
  1. Run the platform channels benchmarks with flutter run --profile with instruments running a Time Profiler probe.

Profile

Screen Shot 2021-12-03 at 3 47 33 PM

All of the time is in the thread_info call.

Version

Dart version 2.16.0 (build 2.16.0-56.0.dev)

Evaluation

Can't we just use the system clock for Dart_TimelineEvent, why does it have to be the clock from thread_info?

Metadata

Metadata

Labels

P2A bug or feature request we're likely to work onarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.customer-flutter

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions