File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33const common = require ( '../common.js' ) ;
44const bench = common . createBenchmark ( main , {
55 n : [ 4e5 ] ,
6+ als : [ 0 , 1 ] ,
67} ) ;
78
8- function main ( { n } ) {
9+ function main ( { n, als } ) {
10+ if ( als ) {
11+ const { AsyncLocalStorage } = require ( 'async_hooks' ) ;
12+ // Run the benchmark inside an AsyncLocalStorage context
13+ new AsyncLocalStorage ( ) . run ( { } , ( ) => queue ( n ) ) ;
14+ } else {
15+ queue ( n ) ;
16+ }
17+ }
18+
19+ function queue ( n ) {
920 let j = 0 ;
1021
1122 function cb ( ) {
Original file line number Diff line number Diff line change 22const common = require ( '../common.js' ) ;
33const bench = common . createBenchmark ( main , {
44 n : [ 12e5 ] ,
5+ als : [ 0 , 1 ] ,
56} ) ;
67
7- function main ( { n } ) {
8+ function main ( { n, als } ) {
9+ if ( als ) {
10+ const { AsyncLocalStorage } = require ( 'async_hooks' ) ;
11+ // Run the benchmark inside an AsyncLocalStorage context.
12+ new AsyncLocalStorage ( ) . run ( { } , ( ) => start ( n ) ) ;
13+ } else {
14+ start ( n ) ;
15+ }
16+ }
17+
18+ function start ( n ) {
819 let counter = n ;
920 bench . start ( ) ;
1021 queueMicrotask ( onNextTick ) ;
Original file line number Diff line number Diff line change @@ -167,16 +167,15 @@ const defaultMicrotaskResourceOpts = { requireManualDestroy: true };
167167function queueMicrotask ( callback ) {
168168 validateFunction ( callback , 'callback' ) ;
169169
170- const contextFrame = AsyncContextFrame . current ( ) ;
171- if ( contextFrame || enabledHooksExist ( ) ) {
170+ if ( enabledHooksExist ( ) ) {
172171 const asyncResource = new AsyncResource (
173172 'Microtask' ,
174173 defaultMicrotaskResourceOpts ,
175174 ) ;
176175 asyncResource . callback = callback ;
177176 enqueueMicrotask ( FunctionPrototypeBind ( runMicrotask , asyncResource ) ) ;
178177 } else {
179- // Fast path: no AsyncLocalStorage in use
178+ // Fast path: V8's CallableTask preserves ContinuationPreservedEmbedderData.
180179 enqueueMicrotask ( callback ) ;
181180 }
182181}
You can’t perform that action at this time.
0 commit comments