Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timers: cross JS/C++ border less frequently for setImmediate() #17064

Closed
wants to merge 1 commit into from

Commits on Nov 16, 2017

  1. 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
    addaleax committed Nov 16, 2017
    Configuration menu
    Copy the full SHA
    8310986 View commit details
    Browse the repository at this point in the history