-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Transfer webview resource buffers #139145
Conversation
src/vs/base/common/buffer.ts
Outdated
@@ -14,8 +14,8 @@ let textDecoder: TextDecoder | null; | |||
|
|||
export class VSBuffer { | |||
|
|||
static alloc(byteLength: number): VSBuffer { | |||
if (hasBuffer) { | |||
static alloc(byteLength: number, forceUseUint8Array = false): VSBuffer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing this low level flag feels wrong, but as I noted in the issue comment I'm not sure if there is a better way to do this
Here's my understanding of what is going on:
For this particular optimization, instead of adding Here's a quick, untested attempt of a change that could be localized to function concatWithoutNodePool(buffers: VSBuffer[]): VSBuffer {
const totalLength = buffers.reduce((prev, curr) => prev + curr.byteLength, 0);
const ret = Buffer.alloc(totalLength);
let offset = 0;
for (let i = 0, len = buffers.length; i < len; i++) {
const element = buffers[i];
ret.set(element.buffer, offset);
offset += element.byteLength;
}
return VSBuffer.wrap(ret);
}
const buffer = VSBuffer.wrap(await streams.consumeStream<Buffer>(stream, chunks => concatWithoutNodePool(chunks))); I will document these findings on cc @deepak1556 |
…nodejs Buffer pool and thus might not be transferrable (See microsoft/vscode#139145) Commit: d1886674451a37c05f5abfacf05e702ecac22fb5
…uffer pool and thus might not be transferrable (See #139145)
@alexdima Reading your comment reminded me of the amazing library See performance:
Therefore I wonder how this web compatible allocator compare to the current VSbuffer.alloc/allocUnsafe. |
Fixes #139145 This updates the webview resource loading to use transferables On desktop, this requires a new way of converting the file stream to a buffer without using the nodejs backing pool
121032d
to
5355e6c
Compare
Thanks @alexdima! I've re-implemented this all in the webview code |
Transfer the underlying buffer of a webview resource load to avoid an extra data copy. This improves performance. The perf improvement is small for normal requests, but becomes more signficant the larger the resource becomes
To support this, I needed to expose a new option that forces VSBuffer to use
UInt8Array
instead of a Node buffer. In my testing, trying to transfer a node Buffer ends up breaking our general ipc buffers and breaks the entire app. Not sure if there's a better way to do this