| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Using == null in code paths that are expected to mostly receive objects, arrays or other more complex data types is not ideal because typecasting these types is very slow. Change to instead check === null || === undefined. Also move one variable assignment in fromString after an if condition that doesn't need it (and returns if truthy). Refs: https://jsperf.com/triple-equals-vs-double-equals/3
|
There are other parts of code outside of Buffer that extensively use == null or != null, some of that isn't code that runs often but then there's stuff like encoding.js and url.js which seems performance sensitive and should probably not be using it. Would people prefer a separate PR for each module or just one? Or none at all? |
Sorry, something went wrong.
|
/cc @bmeurer what do you think? I'd expect this to be optimizable by the engine but maybe I'm missing something about the spec? |
Sorry, something went wrong.
|
Node doesn't have document.all, so ==null could probably be made as fast as the explicit ==null||==undefined. But the performance behavior will be different from that in Chrome then. Is that something we'd like to have? cc @psmarshall |
Sorry, something went wrong.
Sorry, something went wrong.
|
(Probably off-topic but) what about document.all necessitates being pessimistic about == null checks in the optimizer? |
Sorry, something went wrong.
|
@Kovensky see https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-all for more info |
Sorry, something went wrong.
|
I see (a quick search just said that was non-standard and “do not use”). Thanks for the reference. Maybe one day it could be optimized in browsers too by only being pessimistic if document.all is ever accessed, but that is definitely an off-topic discussion. |
Sorry, something went wrong.
|
@Kovensky, FWIW also see tc39/ecma262#673, which brings the odd behaviors of document.all into Annex B, so technically "spec-compliant". See latest spec. Since that PR was merged pretty recently, the integration of that ECMAScript to the HTML Standard is pending (whatwg/html#3015). |
Sorry, something went wrong.
|
It would be great if v8 handles this better but it will take a while until this would get into Node.js. This is a trivial fix that improves the current situation and therefore I would definitely like to land this. |
Sorry, something went wrong.
|
It would be nice to have V8 optimize the single equals case for null/undefined, unless they can implement something that sees the double check pattern and optimizes it as a special case. |
Sorry, something went wrong.
|
@mscdex but you do not mind landing this for the time being, do you? Because if you are good with this, it could land. |
Sorry, something went wrong.
|
@BridgeAR It's fine for now I suppose. |
Sorry, something went wrong.
Using == null in code paths that are expected to mostly receive objects, arrays or other more complex data types is not ideal because typecasting these types is very slow. Change to instead check === null || === undefined. Also move one variable assignment in fromString after an if condition that doesn't need it (and returns if truthy). PR-URL: #15178 Refs: https://jsperf.com/triple-equals-vs-double-equals/3 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Using == null in code paths that are expected to mostly receive objects, arrays or other more complex data types is not ideal because typecasting these types is very slow. Change to instead check === null || === undefined. Also move one variable assignment in fromString after an if condition that doesn't need it (and returns if truthy). PR-URL: nodejs#15178 Refs: https://jsperf.com/triple-equals-vs-double-equals/3 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Using == null in code paths that are expected to mostly receive objects, arrays or other more complex data types is not ideal because typecasting these types is very slow. Change to instead check === null || === undefined. Also move one variable assignment in fromString after an if condition that doesn't need it (and returns if truthy). PR-URL: #15178 Refs: https://jsperf.com/triple-equals-vs-double-equals/3 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
|
should this land in LTS? If so it will need to bake a bit longer. Please change labels as appropriate |
Sorry, something went wrong.
|
Not certain. I'll need to run benchmarks to see if this change makes a difference on v6.x given the different V8. That said, if it does make a difference this might be possible to backport almost immediately since it doesn't functionally change anything just makes the check more V8 friendly. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Using == null in code paths that are expected to mostly receive objects, arrays or other more complex data types is not great because typecasting these types is very slow. Change to instead check === null || === undefined.
Here's the benchmark:
and here's the old vs old, just to show that the string slowdown is probably just within margin of error:
For reference, == vs === is about 10x slower: https://jsperf.com/triple-equals-vs-double-equals/3
Checklist
Affected core subsystem(s)
buffer