-
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: ~2x slowdown in master compared to v12.x #32226
Comments
@mscdex Can you provide the output |
Added. |
Additionally, I'm using gcc 7.4.0 to compile if that matters. |
Can you try #32116? If this is some regression on V8, it might already be fixed (or it might be worse on 8.1, but let's hope not). |
The prof output makes it seem like the reason is that Or it’s unrelated to that, but that’s not what the prof output says. |
@mmarchini The V8 8.1 branch has the same performance as master. |
|
I've also now tried:
All changes made little to no difference. |
@mscdex do you see similar results with any of the benchmarks from benchmark/buffers? Maybe some benchmark similar to your private code? |
@mmarchini Yes, for example:
|
The |
If that helps, I can also see the same performance degradation on 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux, gcc 7.5.0:
|
@addaleax I think there's a mix of atomics and mutexes locks going on: And looking at V8 source code, they explicitly use mutexes (backing-store.cc#L518, mutex.h#L292, mutex.cc#L14-L32). Looking at git blame and git history, the perf regression was likely introduced on v8/v8@b6b7de0, but I'm not entirely sure. If this is a V8 issue, it would be good to have a more isolated repro available. Edit: The third time the commit above was reverted, it was because V8 identified a performance regression. Maybe the regression was not fixed yet? |
I'm not sure if there's a way to trigger it without using any node-specific API, but here is a more minimal example that should still reproduce the issue: 'use strict';
const buf = Buffer.alloc(100, 'a');
console.time('slice');
for (let i = 0; i < 1e7; ++i)
buf.utf8Slice(0, 32);
console.timeEnd('slice'); |
Sorry, should've been more specific, a V8-only repro. Or maybe a small Node.js repro is enough in this case? cc @nodejs/v8 |
@mmarchini Right, like I said I don't know that that's possible because looking through the V8 source, there are not many places that call |
The problem is not specific to Same example as @mscdex but with ArrayBuffer, still the same performance drop 'use strict';
const len = 512;
const buf = new ArrayBuffer(len);
const view = new Int32Array(buf);
console.time('toString ' + len);
for (let i = 0; i < 1e6; i++) {
view.slice(0, 32).toString();
}
console.timeEnd('toString ' + len); |
Is it possible Node could avoid at least some of these regressions by safely caching the result of |
I don't think it would be a good idea. Besides, even if you solve the problem for this artificial benchmark, this won't apply to the real world apps |
@mmomtchev I was thinking more along the lines of caching it at the time of Buffer construction (or lazily caching it), which would apply to everything. However I'm not sure if the value returned by |
@mscdex, yes, I was thinking about caching the returned value There is a Google document on the new BackingStore framework: https://docs.google.com/document/d/1sTc_jRL87Fu175Holm5SV0kajkseGl2r8ifGY76G35k/edit#heading=h.5irk4csrpu0y |
In fact, when thinking again, there is no reason why very small Buffers are not impacted - I am looking at the numbers and I wonder if it has something to do with the JIT - I don't really have an explanation |
@mmomtchev just ran into this performance issue too and it seems like there are two issues at play:
Now, for cases where the buffer is allocated using |
I guess the question there would be … how would we do that in a way that’s more efficient than calling |
@addaleax - is my understanding below correct?
|
Not really – Buffer objects are
There is no underlying object in that sense, but yes, in order to be able to call a method on an object, you need to hold a reference to it.
Yes, that’s always true. |
Got it, so would it make sense to store the the backing store pointer at c'tor time (via |
This removes all usages of GetBackingStore in startup. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44078 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in WASI. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44077 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in modules. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44076 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
This removes all usages of GetBackingStore in `node-api`. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44075 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore without any entries in the `CODEOWNERS` file. For the most part this is a pretty straightforward review; except `SPREAD_BUFFER_ARG` and the changes to `CopyArrayBuffer`. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44080 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in `crypto`. See the linked issue for an explanation. Note: I am not sure of the lifetime semantics intended by `ArrayBufferOrViewContents` -- I am pretty sure it is correct based on a manual audit of the callsites, but please ensure that it is correct. Refs: #32226 Refs: #43921 PR-URL: #44079 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Original commit message: Add more efficient API for accesssing ArrayBuffer raw data Raw data access is already possible via GetBackingStore()->GetData(). This API exposes a more efficient way for accessing JSArrayBuffer::backing_store (which, despite the confusing name, is no the BackingStore but its raw data pointer). Bug: v8:10343 Change-Id: I695cea91e2c3de75ce6c86bac6e413ce6617958b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3764341 Reviewed-by: Camillo Bruni <[email protected]> Commit-Queue: Marja Hölttä <[email protected]> Cr-Commit-Position: refs/heads/main@{#81745} Refs: v8/v8@00704f5 Refs: #32226 PR-URL: #43921 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Feng Yu <[email protected]>
This removes all usages of GetBackingStore in startup. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44078 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in WASI. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44077 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in modules. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44076 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
This removes all usages of GetBackingStore in `node-api`. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44075 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore without any entries in the `CODEOWNERS` file. For the most part this is a pretty straightforward review; except `SPREAD_BUFFER_ARG` and the changes to `CopyArrayBuffer`. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44080 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in `crypto`. See the linked issue for an explanation. Note: I am not sure of the lifetime semantics intended by `ArrayBufferOrViewContents` -- I am pretty sure it is correct based on a manual audit of the callsites, but please ensure that it is correct. Refs: #32226 Refs: #43921 PR-URL: #44079 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Original commit message: Add more efficient API for accesssing ArrayBuffer raw data Raw data access is already possible via GetBackingStore()->GetData(). This API exposes a more efficient way for accessing JSArrayBuffer::backing_store (which, despite the confusing name, is no the BackingStore but its raw data pointer). Bug: v8:10343 Change-Id: I695cea91e2c3de75ce6c86bac6e413ce6617958b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3764341 Reviewed-by: Camillo Bruni <[email protected]> Commit-Queue: Marja Hölttä <[email protected]> Cr-Commit-Position: refs/heads/main@{#81745} Refs: v8/v8@00704f5 Refs: #32226 PR-URL: #43921 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Feng Yu <[email protected]>
This removes all usages of GetBackingStore in startup. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44078 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in WASI. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44077 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in modules. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44076 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
This removes all usages of GetBackingStore in `node-api`. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44075 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore without any entries in the `CODEOWNERS` file. For the most part this is a pretty straightforward review; except `SPREAD_BUFFER_ARG` and the changes to `CopyArrayBuffer`. See the linked issue for an explanation. Refs: #32226 Refs: #43921 PR-URL: #44080 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in `crypto`. See the linked issue for an explanation. Note: I am not sure of the lifetime semantics intended by `ArrayBufferOrViewContents` -- I am pretty sure it is correct based on a manual audit of the callsites, but please ensure that it is correct. Refs: #32226 Refs: #43921 PR-URL: #44079 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Original commit message: Add more efficient API for accesssing ArrayBuffer raw data Raw data access is already possible via GetBackingStore()->GetData(). This API exposes a more efficient way for accessing JSArrayBuffer::backing_store (which, despite the confusing name, is no the BackingStore but its raw data pointer). Bug: v8:10343 Change-Id: I695cea91e2c3de75ce6c86bac6e413ce6617958b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3764341 Reviewed-by: Camillo Bruni <[email protected]> Commit-Queue: Marja Hölttä <[email protected]> Cr-Commit-Position: refs/heads/main@{#81745} Refs: v8/v8@00704f5 Refs: nodejs#32226 PR-URL: nodejs#43921 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Feng Yu <[email protected]>
This removes all usages of GetBackingStore in startup. See the linked issue for an explanation. Refs: nodejs#32226 Refs: nodejs#43921 PR-URL: nodejs#44078 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in WASI. See the linked issue for an explanation. Refs: nodejs#32226 Refs: nodejs#43921 PR-URL: nodejs#44077 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in modules. See the linked issue for an explanation. Refs: nodejs#32226 Refs: nodejs#43921 PR-URL: nodejs#44076 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
This removes all usages of GetBackingStore in `node-api`. See the linked issue for an explanation. Refs: nodejs#32226 Refs: nodejs#43921 PR-URL: nodejs#44075 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore without any entries in the `CODEOWNERS` file. For the most part this is a pretty straightforward review; except `SPREAD_BUFFER_ARG` and the changes to `CopyArrayBuffer`. See the linked issue for an explanation. Refs: nodejs#32226 Refs: nodejs#43921 PR-URL: nodejs#44080 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
This removes all usages of GetBackingStore in `crypto`. See the linked issue for an explanation. Note: I am not sure of the lifetime semantics intended by `ArrayBufferOrViewContents` -- I am pretty sure it is correct based on a manual audit of the callsites, but please ensure that it is correct. Refs: nodejs#32226 Refs: nodejs#43921 PR-URL: nodejs#44079 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Linux foo 5.0.0-36-generic #39~18.04.1-Ubuntu SMP Tue Nov 12 11:09:50 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
I was running some benchmarks (for private code) and noticed a significant slowdown with some Buffer methods. Here is a comparison of the C++ portion of
--prof
between v12.16.1 and master:v12.16.1:
master:
As you will see, master has these additional items at the top of the list:
Is there some way we can avoid this slowdown?
The text was updated successfully, but these errors were encountered: