Commit fd501b3
timers: cross JS/C++ border less frequently
This removes the `process._needImmediateCallback` property
and its semantics of having a 1/0 switch that tells C++ whether
immediates are currently scheduled.
Instead, a counter keeping track of all immediates is created,
that can be increased on `setImmediate()` or decreased when an
immediate is run or cleared.
This is faster, because rather than reading/writing a C++ getter,
this operation can be performed as a direct memory read/write via
a typed array. The only C++ call that is left to make is
activating the native handles upon creation of the first
`Immediate` after the queue is empty.
One other (good!) side-effect is that `immediate._destroyed` now
reliably tells whether an `immediate` is still scheduled to run or not.
Also, as a nice extra, this should make it easier to implement
an internal variant of `setImmediate` for C++ that piggybacks
off the same mechanism, which should be useful at least for
async hooks and HTTP/2.
Benchmark results:
$ ./node benchmark/compare.js --new ./node --old ./node-master-1b093cb93df0 --runs 10 --filter immediate timers | Rscript benchmark/compare.R
[00:08:53|% 100| 4/4 files | 20/20 runs | 1/1 configs]: Done
improvement confidence p.value
timers/immediate.js type="breadth" thousands=2000 25.61 % ** 1.432301e-03
timers/immediate.js type="breadth1" thousands=2000 7.66 % 1.320233e-01
timers/immediate.js type="breadth4" thousands=2000 4.61 % 5.669053e-01
timers/immediate.js type="clear" thousands=2000 311.40 % *** 3.896291e-07
timers/immediate.js type="depth" thousands=2000 17.54 % ** 9.755389e-03
timers/immediate.js type="depth1" thousands=2000 17.09 % *** 7.176229e-04
timers/set-immediate-breadth-args.js millions=5 10.63 % * 4.250034e-02
timers/set-immediate-breadth.js millions=10 20.62 % *** 9.150439e-07
timers/set-immediate-depth-args.js millions=10 17.97 % *** 6.819135e-10
PR-URL: #17064
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>1 parent 9f282dd commit fd501b3Copy full SHA for fd501b3
Expand file treeCollapse file tree
4 files changed
+69
-73
lines changedOpen diff view settings
Collapse file
+24-22Lines changed: 24 additions & 22 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
47 | 47 | |
48 | 48 | |
49 | 49 | |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
50 | 57 | |
51 | 58 | |
52 | 59 | |
| ||
742 | 749 | |
743 | 750 | |
744 | 751 | |
745 | | - |
746 | | - |
747 | | - |
748 | | - |
749 | | - |
750 | | - |
751 | | - |
752 | 752 | |
753 | 753 | |
| 754 | + |
754 | 755 | |
755 | 756 | |
756 | 757 | |
| ||
762 | 763 | |
763 | 764 | |
764 | 765 | |
765 | | - |
766 | 766 | |
767 | 767 | |
768 | 768 | |
769 | | - |
770 | | - |
| 769 | + |
| 770 | + |
771 | 771 | |
| 772 | + |
| 773 | + |
| 774 | + |
| 775 | + |
| 776 | + |
772 | 777 | |
773 | 778 | |
774 | 779 | |
| ||
870 | 875 | |
871 | 876 | |
872 | 877 | |
873 | | - |
874 | | - |
875 | | - |
876 | | - |
| 878 | + |
| 879 | + |
| 880 | + |
877 | 881 | |
878 | 882 | |
879 | 883 | |
| ||
884 | 888 | |
885 | 889 | |
886 | 890 | |
887 | | - |
888 | | - |
889 | | - |
890 | | - |
| 891 | + |
| 892 | + |
891 | 893 | |
| 894 | + |
| 895 | + |
| 896 | + |
| 897 | + |
892 | 898 | |
893 | 899 | |
894 | 900 | |
895 | 901 | |
896 | 902 | |
897 | | - |
898 | | - |
899 | | - |
900 | | - |
901 | 903 | |
Collapse file
+6Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
267 | 267 | |
268 | 268 | |
269 | 269 | |
| 270 | + |
270 | 271 | |
271 | 272 | |
272 | 273 | |
| ||
486 | 487 | |
487 | 488 | |
488 | 489 | |
| 490 | + |
| 491 | + |
| 492 | + |
| 493 | + |
| 494 | + |
489 | 495 | |
490 | 496 | |
491 | 497 | |
|
Collapse file
+4Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
601 | 601 | |
602 | 602 | |
603 | 603 | |
| 604 | + |
| 605 | + |
604 | 606 | |
605 | 607 | |
606 | 608 | |
| ||
696 | 698 | |
697 | 699 | |
698 | 700 | |
| 701 | + |
| 702 | + |
699 | 703 | |
700 | 704 | |
701 | 705 | |
|
Collapse file
+35-51Lines changed: 35 additions & 51 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
399 | 399 | |
400 | 400 | |
401 | 401 | |
402 | | - |
403 | | - |
404 | | - |
405 | | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | | - |
412 | | - |
413 | | - |
414 | | - |
415 | | - |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | | - |
421 | 402 | |
422 | 403 | |
423 | 404 | |
| ||
3274 | 3255 | |
3275 | 3256 | |
3276 | 3257 | |
3277 | | - |
3278 | | - |
3279 | | - |
3280 | | - |
3281 | | - |
3282 | | - |
3283 | | - |
| 3258 | + |
| 3259 | + |
| 3260 | + |
| 3261 | + |
| 3262 | + |
| 3263 | + |
| 3264 | + |
3284 | 3265 | |
3285 | 3266 | |
| 3267 | + |
| 3268 | + |
| 3269 | + |
| 3270 | + |
3286 | 3271 | |
3287 | | - |
3288 | | - |
3289 | | - |
3290 | | - |
3291 | | - |
| 3272 | + |
| 3273 | + |
3292 | 3274 | |
3293 | | - |
3294 | | - |
3295 | | - |
| 3275 | + |
| 3276 | + |
| 3277 | + |
| 3278 | + |
| 3279 | + |
| 3280 | + |
3296 | 3281 | |
3297 | | - |
3298 | | - |
| 3282 | + |
| 3283 | + |
3299 | 3284 | |
3300 | | - |
3301 | 3285 | |
3302 | | - |
3303 | | - |
3304 | | - |
3305 | | - |
3306 | | - |
3307 | | - |
3308 | | - |
3309 | | - |
| 3286 | + |
| 3287 | + |
| 3288 | + |
| 3289 | + |
| 3290 | + |
| 3291 | + |
3310 | 3292 | |
3311 | 3293 | |
3312 | 3294 | |
| ||
3533 | 3515 | |
3534 | 3516 | |
3535 | 3517 | |
3536 | | - |
3537 | | - |
3538 | | - |
3539 | | - |
3540 | | - |
3541 | | - |
| 3518 | + |
| 3519 | + |
| 3520 | + |
| 3521 | + |
| 3522 | + |
3542 | 3523 | |
3543 | 3524 | |
3544 | 3525 | |
| ||
3664 | 3645 | |
3665 | 3646 | |
3666 | 3647 | |
| 3648 | + |
| 3649 | + |
| 3650 | + |
3667 | 3651 | |
3668 | 3652 | |
3669 | 3653 | |
|
0 commit comments