@@ -60,7 +60,7 @@ function setupNextTick() {
60
60
// Grab the constants necessary for working with internal arrays.
61
61
const { kInit, kDestroy, kAsyncIdCounter } = async_wrap . constants ;
62
62
const { async_id_symbol, trigger_async_id_symbol } = async_wrap ;
63
- var nextTickQueue = new NextTickQueue ( ) ;
63
+ const nextTickQueue = new NextTickQueue ( ) ;
64
64
var microtasksScheduled = false ;
65
65
66
66
// Used to run V8's micro task queue.
@@ -99,7 +99,6 @@ function setupNextTick() {
99
99
const microTasksTickObject = {
100
100
callback : runMicrotasksCallback ,
101
101
args : undefined ,
102
- domain : null ,
103
102
[ async_id_symbol ] : 0 ,
104
103
[ trigger_async_id_symbol ] : 0
105
104
} ;
@@ -125,35 +124,13 @@ function setupNextTick() {
125
124
}
126
125
}
127
126
128
- function _combinedTickCallback ( args , callback ) {
129
- if ( args === undefined ) {
130
- callback ( ) ;
131
- } else {
132
- switch ( args . length ) {
133
- case 1 :
134
- callback ( args [ 0 ] ) ;
135
- break ;
136
- case 2 :
137
- callback ( args [ 0 ] , args [ 1 ] ) ;
138
- break ;
139
- case 3 :
140
- callback ( args [ 0 ] , args [ 1 ] , args [ 2 ] ) ;
141
- break ;
142
- default :
143
- callback ( ...args ) ;
144
- }
145
- }
146
- }
147
-
148
127
// Run callbacks that have no domain.
149
128
// Using domains will cause this to be overridden.
150
129
function _tickCallback ( ) {
151
130
do {
152
131
while ( tickInfo [ kIndex ] < tickInfo [ kLength ] ) {
153
132
++ tickInfo [ kIndex ] ;
154
133
const tock = nextTickQueue . shift ( ) ;
155
- const callback = tock . callback ;
156
- const args = tock . args ;
157
134
158
135
// CHECK(Number.isSafeInteger(tock[async_id_symbol]))
159
136
// CHECK(tock[async_id_symbol] > 0)
@@ -173,10 +150,11 @@ function setupNextTick() {
173
150
if ( async_hook_fields [ kDestroy ] > 0 )
174
151
emitDestroy ( tock [ async_id_symbol ] ) ;
175
152
176
- // Using separate callback execution functions allows direct
177
- // callback invocation with small numbers of arguments to avoid the
178
- // performance hit associated with using `fn.apply()`
179
- _combinedTickCallback ( args , callback ) ;
153
+ const callback = tock . callback ;
154
+ if ( tock . args === undefined )
155
+ callback ( ) ;
156
+ else
157
+ Reflect . apply ( callback , undefined , tock . args ) ;
180
158
181
159
emitAfter ( tock [ async_id_symbol ] ) ;
182
160
@@ -191,11 +169,21 @@ function setupNextTick() {
191
169
192
170
class TickObject {
193
171
constructor ( callback , args , asyncId , triggerAsyncId ) {
172
+ // this must be set to null first to avoid function tracking
173
+ // on the hidden class, revisit in V8 versions after 6.2
174
+ this . callback = null ;
194
175
this . callback = callback ;
195
176
this . args = args ;
196
- this . domain = process . domain || null ;
177
+
197
178
this [ async_id_symbol ] = asyncId ;
198
179
this [ trigger_async_id_symbol ] = triggerAsyncId ;
180
+
181
+ if ( async_hook_fields [ kInit ] > 0 ) {
182
+ emitInit ( asyncId ,
183
+ 'TickObject' ,
184
+ triggerAsyncId ,
185
+ this ) ;
186
+ }
199
187
}
200
188
}
201
189
@@ -220,13 +208,14 @@ function setupNextTick() {
220
208
args [ i - 1 ] = arguments [ i ] ;
221
209
}
222
210
223
- const asyncId = ++ async_id_fields [ kAsyncIdCounter ] ;
224
- const triggerAsyncId = initTriggerId ( ) ;
225
- const obj = new TickObject ( callback , args , asyncId , triggerAsyncId ) ;
226
- nextTickQueue . push ( obj ) ;
211
+ // In V8 6.2, moving tickInfo & async_id_fields[kAsyncIdCounter] into the
212
+ // TickObject incurs a significant performance penalty in the
213
+ // next-tick-breadth-args benchmark (revisit later)
227
214
++ tickInfo [ kLength ] ;
228
- if ( async_hook_fields [ kInit ] > 0 )
229
- emitInit ( asyncId , 'TickObject' , triggerAsyncId , obj ) ;
215
+ nextTickQueue . push ( new TickObject ( callback ,
216
+ args ,
217
+ ++ async_id_fields [ kAsyncIdCounter ] ,
218
+ initTriggerId ( ) ) ) ;
230
219
}
231
220
232
221
// `internalNextTick()` will not enqueue any callback when the process is
@@ -240,10 +229,6 @@ function setupNextTick() {
240
229
if ( process . _exiting )
241
230
return ;
242
231
243
- if ( triggerAsyncId === null ) {
244
- triggerAsyncId = async_hooks . initTriggerId ( ) ;
245
- }
246
-
247
232
var args ;
248
233
switch ( arguments . length ) {
249
234
case 2 : break ;
@@ -256,11 +241,15 @@ function setupNextTick() {
256
241
args [ i - 2 ] = arguments [ i ] ;
257
242
}
258
243
259
- const asyncId = ++ async_id_fields [ kAsyncIdCounter ] ;
260
- const obj = new TickObject ( callback , args , asyncId , triggerAsyncId ) ;
261
- nextTickQueue . push ( obj ) ;
244
+ if ( triggerAsyncId === null )
245
+ triggerAsyncId = initTriggerId ( ) ;
246
+ // In V8 6.2, moving tickInfo & async_id_fields[kAsyncIdCounter] into the
247
+ // TickObject incurs a significant performance penalty in the
248
+ // next-tick-breadth-args benchmark (revisit later)
262
249
++ tickInfo [ kLength ] ;
263
- if ( async_hook_fields [ kInit ] > 0 )
264
- emitInit ( asyncId , 'TickObject' , triggerAsyncId , obj ) ;
250
+ nextTickQueue . push ( new TickObject ( callback ,
251
+ args ,
252
+ ++ async_id_fields [ kAsyncIdCounter ] ,
253
+ triggerAsyncId ) ) ;
265
254
}
266
255
}
0 commit comments