lib: consistent this in callbacks#14645
Conversation
|
Needs a CITGM run and some benchmarks too, although I imagine the consistency aspect overrides anything the benchmarks show unless it's a severe perf hit. |
There was a problem hiding this comment.
This is the kind of thing we definitely need to benchmark... both here and nextTick() especially because in both scenarios a different type of value is being used with the spread operator (special arguments vs array).
There was a problem hiding this comment.
The current next-tick benchmarks do not test the code modified here. I'll add a commit to include this code path in the benchmarks.
There was a problem hiding this comment.
There are a few other combinations that should be benchmarked:
cb.bind(undefined)function (...args) { cb(...args) }(...args) => cb(...args)
I'll try to check some.
There was a problem hiding this comment.
OK, I went back to .apply(undefined, arguments) which probably won't correct as many edge cases, but is better than the current .apply(null, arguments) in that regard and doesn't have a negative perf hit.
|
@mscdex I updated the Running the resulting benchmarks shows no significant performance difference. Command I ran to generate data: $ node benchmark/compare.js --old ./node-master --new ./node-strictify --filter next-tick --filter args process | tee compare.csvCommand I ran to analyze it: $ cat compare.csv | Rscript benchmark/compare.RResult: improvement confidence p.value
process/next-tick-breadth-args.js millions=2 -0.48 % 0.3246212
process/next-tick-depth-args.js millions=12 0.42 % 0.1323853Increasing the number of runs might help decrease the p-values a bit, but so far, it seems like the change does not significantly impact performance. |
|
@nodejs/ctc This is |
There was a problem hiding this comment.
There are a few other combinations that should be benchmarked:
cb.bind(undefined)function (...args) { cb(...args) }(...args) => cb(...args)
I'll try to check some.
|
Going to rebase and force push so I can check the |
|
On the |
* add `use strict' * change checks that `this` is mapped to `global` in sloppy mode to checks that `this` is `undefined` * modify arguments to assertions to match docs (actual first, expected second) * add blank line below `common` declaration per test writing guide * use `assert.ifError()` as appropriate
This change normalizes a few situations where a callback might be invoked with
thisset toundefinedin one case, butnullin a very similar case.First commit:
Second commit:
Third commit:
Fourth commit:
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
test process lib fs