@@ -192,7 +192,11 @@ impl StaticExecutor {
192
192
let ( runnable, task) = Builder :: new ( )
193
193
. propagate_panic ( true )
194
194
. spawn ( |( ) | future, self . schedule ( ) ) ;
195
- runnable. schedule ( ) ;
195
+
196
+ // `Runnable::schedule` has an extra clone/drop of the Waker, which can
197
+ // be skipped by directly scheduling instead of calling `Runnable::schedule`.
198
+ Self :: schedule_runnable ( & self . state , runnable) ;
199
+
196
200
task
197
201
}
198
202
@@ -219,7 +223,11 @@ impl StaticExecutor {
219
223
. propagate_panic ( true )
220
224
. spawn_unchecked ( |( ) | future, self . schedule ( ) )
221
225
} ;
222
- runnable. schedule ( ) ;
226
+
227
+ // `Runnable::schedule` has an extra clone/drop of the Waker, which can
228
+ // be skipped by directly scheduling instead of calling `Runnable::schedule`.
229
+ Self :: schedule_runnable ( & self . state , runnable) ;
230
+
223
231
task
224
232
}
225
233
@@ -294,11 +302,16 @@ impl StaticExecutor {
294
302
let state: & ' static State = & self . state ;
295
303
// TODO: If possible, push into the current local queue and notify the ticker.
296
304
move |runnable| {
297
- let result = state. queue . push ( runnable) ;
298
- debug_assert ! ( result. is_ok( ) ) ; // Since we use unbounded queue, push will never fail.
299
- state. notify ( ) ;
305
+ Self :: schedule_runnable ( state, runnable) ;
300
306
}
301
307
}
308
+
309
+ #[ inline]
310
+ fn schedule_runnable ( state : & ' static State , runnable : Runnable ) {
311
+ let result = state. queue . push ( runnable) ;
312
+ debug_assert ! ( result. is_ok( ) ) ; // Since we use unbounded queue, push will never fail.
313
+ state. notify ( ) ;
314
+ }
302
315
}
303
316
304
317
impl Default for StaticExecutor {
@@ -375,7 +388,11 @@ impl StaticLocalExecutor {
375
388
let ( runnable, task) = Builder :: new ( )
376
389
. propagate_panic ( true )
377
390
. spawn_local ( |( ) | future, self . schedule ( ) ) ;
378
- runnable. schedule ( ) ;
391
+
392
+ // `Runnable::schedule` has an extra clone/drop of the Waker, which can
393
+ // be skipped by directly scheduling instead of calling `Runnable::schedule`.
394
+ Self :: schedule_runnable ( & self . state , runnable) ;
395
+
379
396
task
380
397
}
381
398
@@ -408,7 +425,11 @@ impl StaticLocalExecutor {
408
425
. propagate_panic ( true )
409
426
. spawn_unchecked ( |( ) | future, self . schedule ( ) )
410
427
} ;
411
- runnable. schedule ( ) ;
428
+
429
+ // `Runnable::schedule` has an extra clone/drop of the Waker, which can
430
+ // be skipped by directly scheduling instead of calling `Runnable::schedule`.
431
+ Self :: schedule_runnable ( & self . state , runnable) ;
432
+
412
433
task
413
434
}
414
435
@@ -480,11 +501,16 @@ impl StaticLocalExecutor {
480
501
let state: & ' static State = & self . state ;
481
502
// TODO: If possible, push into the current local queue and notify the ticker.
482
503
move |runnable| {
483
- let result = state. queue . push ( runnable) ;
484
- debug_assert ! ( result. is_ok( ) ) ; // Since we use unbounded queue, push will never fail.
485
- state. notify ( ) ;
504
+ Self :: schedule_runnable ( state, runnable) ;
486
505
}
487
506
}
507
+
508
+ #[ inline]
509
+ fn schedule_runnable ( state : & ' static State , runnable : Runnable ) {
510
+ let result = state. queue . push ( runnable) ;
511
+ debug_assert ! ( result. is_ok( ) ) ; // Since we use unbounded queue, push will never fail.
512
+ state. notify ( ) ;
513
+ }
488
514
}
489
515
490
516
impl Default for StaticLocalExecutor {
0 commit comments