-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Buffer.length became significantelly slower in 3.x #2463
Comments
Probably because |
It makes sense since in 3.0.0 it's a getter non-own property and previously it was just a simple own data property. Probably we can just attach it to an instance. /cc @trevnorris |
I am not sure if this benchmark is correct, but it shows the difference 'use strict';
const common = require('../common');
const bench = common.createBenchmark(main, {
n: [10e3, 10e4, 10e5, 10e6, 10e7, 10e8]
});
function main(conf) {
const buffer = new Buffer(conf.n | 0);
bench.start();
for (var i = 0; i < buffer.length; i++);
bench.end(n);
} And this is the result I got with the latest master,
And the following with v2.5.0,
|
@vkurchatkin What do you mean by "can just attach it to an instance"? @matklad Yeah. Sorry about this. Thanks to everything W3C related, properties must be a getter. |
I mean just stick |
@vkurchatkin we don't have a constructor anymore. It's now essentially |
Can this be closed? It's not a won't fix, but a can't fix. Part of what we inherited by needing to use typed arrays. |
@trevnorris Can we maintain a |
@thefourtheye It's not a property. It's a getter on the typed array. And since we can only "inherit" the typed array by setting its And if the size of the Buffer could be altered, then v8 will have to provide a new API that alerts us when that happens. Otherwise we'll have no idea when the array size changed. |
Yup that's what I had in my mind. |
@thefourtheye Eh? The only way to do that from JS is to use Either way we're taking a performance hit. Not to mention the fact that we'll have no way of knowing when the user runs I'm far more concerned about construction time then loop iteration time. /cc @domenic I'm sure you can rule in from the ECMA side what could potentially happen if we override the |
I was thinking more like if (arg < 0 || arg !== arg)
arg = 0;
const buf = allocate(arg);
buf.length = arg;
return buf; and maintaining there onwards. |
@thefourtheye Doing @trevnorris right, you could add a per-instance property that shadows the inherited property, using The real fix here is just to get V8 to make this fast, like |
This is fixed by #2801, it seems. |
Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: #2463 PR-URL: #2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Fixed by acb6779. |
Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: #2463 PR-URL: #2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Cherry-picked from Node.js: commit acb6779c19abf248a4c6d5c3d3389805e7ee8b8d Author: Fedor Indutny <[email protected]> Date: Thu Sep 10 12:26:50 2015 -0700 deps: cherry-pick 6da51b4 from v8's upstream Original commit message: TypedArray accessor detection: consider entire prototype chain When looking up a special accessor for known TypedArray fields ("length", "byteLength", "byteOffset"), consider the entire prototype chain, not only the direct prototype. This allows subclasses of TypedArrays to benefit from fast specialized accesses. Review URL: https://codereview.chromium.org/1313493005 Cr-Commit-Position: refs/heads/master@{#30678} Benchmark results: buffers/buffer-iterate.js size=16386 type=slow method=for n=1000: ./node: 71607 node: 8702.3 ............ 722.85% Improvement depends on the code, but generally brings us back to the performance that we had before the v8 update (if not making it faster). Fixes: nodejs/node#2463 PR-URL: nodejs/node#2801 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
May be it's a know issue, but I was surprised to discover this behavior in my benchmarks.
Consider this two snippets of code:
and
under v2.5.0 their performance is indistinguishable, but under v3.0.0 or v3.1.0 the first version causes 1.5x slowdown of my whole benchmark.
The text was updated successfully, but these errors were encountered: