@@ -37,18 +37,7 @@ void _microtaskLoop() {
3737 var next = entry.next;
3838 _nextCallback = next;
3939 if (next == null ) _lastCallback = null ;
40- if (const bool .fromEnvironment ("dart.vm.product" ) ||
41- ! _MicrotaskMirrorQueue ._shouldProfileMicrotasks) {
42- (entry.callback)();
43- } else {
44- final callbackStartTime = Timeline .now;
45- (entry.callback)();
46- final callbackEndTime = Timeline .now;
47- _MicrotaskMirrorQueue ._onAsyncCallbackComplete (
48- callbackStartTime,
49- callbackEndTime,
50- );
51- }
40+ _microtaskEntryCallback (entry)();
5241 }
5342}
5443
@@ -73,10 +62,7 @@ void _startMicrotaskLoop() {
7362/// microtasks, but as part of the current system event.
7463void _scheduleAsyncCallback (_AsyncCallback callback) {
7564 _AsyncCallbackEntry newEntry = _AsyncCallbackEntry (callback);
76- if (! const bool .fromEnvironment ("dart.vm.product" ) &&
77- _MicrotaskMirrorQueue ._shouldProfileMicrotasks) {
78- _MicrotaskMirrorQueue ._onScheduleAsyncCallback ();
79- }
65+ _beforeScheduleMicrotaskCallback ();
8066 _AsyncCallbackEntry ? lastCallback = _lastCallback;
8167 if (lastCallback == null ) {
8268 _nextCallback = _lastCallback = newEntry;
@@ -102,10 +88,7 @@ void _schedulePriorityAsyncCallback(_AsyncCallback callback) {
10288 return ;
10389 }
10490 _AsyncCallbackEntry entry = _AsyncCallbackEntry (callback);
105- if (! const bool .fromEnvironment ("dart.vm.product" ) &&
106- _MicrotaskMirrorQueue ._shouldProfileMicrotasks) {
107- _MicrotaskMirrorQueue ._onSchedulePriorityAsyncCallback ();
108- }
91+ _beforeSchedulePriorityCallback ();
10992 _AsyncCallbackEntry ? lastPriorityCallback = _lastPriorityCallback;
11093 if (lastPriorityCallback == null ) {
11194 entry.next = _nextCallback;
@@ -121,6 +104,20 @@ void _schedulePriorityAsyncCallback(_AsyncCallback callback) {
121104 }
122105}
123106
107+ // Overridden by VM.
108+ @pragma ("dart2js:prefer-inline" )
109+ @pragma ("dart2wasm:prefer-inline" )
110+ void _beforeSchedulePriorityCallback () {}
111+
112+ @pragma ("dart2js:prefer-inline" )
113+ @pragma ("dart2wasm:prefer-inline" )
114+ void _beforeScheduleMicrotaskCallback () {}
115+
116+ @pragma ("dart2js:prefer-inline" )
117+ @pragma ("dart2wasm:prefer-inline" )
118+ void Function () _microtaskEntryCallback (_AsyncCallbackEntry entry) =>
119+ entry.callback;
120+
124121/// Runs a function asynchronously.
125122///
126123/// Callbacks registered through this function are always executed in order and
@@ -167,22 +164,6 @@ void scheduleMicrotask(void Function() callback) {
167164 Zone .current.scheduleMicrotask (Zone .current.bindCallbackGuarded (callback));
168165}
169166
170- @pragma ("vm:entry-point" , ! const bool .fromEnvironment ("dart.vm.product" ))
171- abstract final class _MicrotaskMirrorQueue {
172- // This will be set to true by the native runtime's
173- // `DartUtils::PrepareAsyncLibrary` when the CLI flag `--profile-microtasks`
174- // is set.
175- @pragma ("vm:entry-point" , ! const bool .fromEnvironment ("dart.vm.product" ))
176- static bool _shouldProfileMicrotasks = false ;
177-
178- // The following methods are only implemented for the native runtime. Those
179- // implementations are in
180- // `sdk/lib/_internal/vm/lib/schedule_microtask_patch.dart`.
181- static void _onScheduleAsyncCallback () {}
182- static void _onSchedulePriorityAsyncCallback () {}
183- static void _onAsyncCallbackComplete (int startTime, int endTime) {}
184- }
185-
186167class _AsyncRun {
187168 /// Schedule the given callback before any other event in the event-loop.
188169 external static void _scheduleImmediate (void Function () callback);
0 commit comments