GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: simplify toggling the buffer zero-fill flag by nornagon · Pull Request #43537 · nodejs/node

Conversation

@nornagon

@nornagon nornagon commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

In Electron, and by default in V8, we enable the V8 memory cage, which
disallows pointers to memory outside of the cage. The zero-fill toggle is
currently implemented as an external ArrayBuffer, which violates this policy
and thus causes a crash when the memory cage is enabled. This PR changes the
zero-fill toggle to be implemented without the use of an external ArrayBuffer.

cc @bnoordhuis who wrote this code back in 27e84dd

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@nodejs-github-bot

nodejs-github-bot commented Jun 22, 2022

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jun 22, 2022
@nornagon nornagon changed the title simplify toggling the buffer zero-fill flag src: simplify toggling the buffer zero-fill flag Jun 22, 2022
@nornagon
nornagon force-pushed the sandbox-compat-zerofill branch from f85cc48 to 2dcab36 Compare June 22, 2022 19:00
@nornagon
src: simplify toggling the buffer zero-fill flag
6c631ca
@nornagon
nornagon force-pushed the sandbox-compat-zerofill branch from 2dcab36 to 6c631ca Compare June 22, 2022 19:04
@bnoordhuis

bnoordhuis commented Jun 22, 2022

Copy link
Copy Markdown
Member

The reason it's an ArrayBuffer is performance. Changing it to a JS->C++ call likely tanks performance all over the place because buffers are used so pervasively.

addaleax and bricss reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nornagon

nornagon commented Jun 22, 2022 via email

Copy link
Copy Markdown
Contributor Author
My intuition is that it shouldn’t be too much slower, do you have a suggestion about what would exercise this path correctly to expose the performance difference?
On Wed, Jun 22, 2022 at 12:57 Ben Noordhuis ***@***.***> wrote: The reason it's an ArrayBuffer is performance. Changing it to a JS->C++ call likely tanks performance all over the place because buffers are used so pervasively. — Reply to this email directly, view it on GitHub <#43537 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABKGACPX2KKBDJ63C5IILLVQNV3HANCNFSM5ZRDR6CQ> . You are receiving this because you authored the thread.Message ID: ***@***.***>
-- j
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Jun 23, 2022

Copy link
Copy Markdown
Member

I think you can try running the buffer benchmarks (see this doc) and see if the patch makes a difference.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Jun 23, 2022

Copy link
Copy Markdown
Member

I started a benchmark CI with this PR: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1159/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Jun 23, 2022

Copy link
Copy Markdown
Member

In Electron, and by default in V8, we enable the V8 memory cage, which
disallows pointers to memory outside of the cage. The zero-fill toggle is
currently implemented as an external ArrayBuffer, which violates this policy
and thus causes a crash when the memory cage is enabled.

Doesn’t that mean that Electron effectively won’t work with any externally provided ArrayBuffer? That seems like a big breaking change, if not for Node.js, then for any addon users?

Nantris reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nornagon

nornagon commented Jun 23, 2022

Copy link
Copy Markdown
Contributor Author

Doesn’t that mean that Electron effectively won’t work with any externally provided ArrayBuffer? That seems like a big breaking change, if not for Node.js, then for any addon users?

Yep, unfortunately it does mean that. It's a tradeoff we've decided to make; I'm writing up our reasoning for it currently, will link when ready.

As for interpreting those benchmark results, I'm not totally sure what I'm looking at, but it seems to indicate that this makes things slower?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Jun 24, 2022

Copy link
Copy Markdown
Member

There seems to be a significant performance drop. Here are the double digit ones with 3 *s:

                                                                              confidence improvement accuracy (*)    (**)   (***)
buffers/buffer-copy.js n=6000000 partial='false' bytes=32768                         ***    -12.74 %       ±5.38%  ±7.20%  ±9.46%
buffers/buffer-copy.js n=6000000 partial='true' bytes=32768                          ***    -32.55 %      ±11.28% ±15.18% ±20.13%
buffers/buffer-creation.js n=600000 len=10 type='slow-allocUnsafe'                   ***    -42.54 %      ±12.06% ±16.13% ±21.14%
buffers/buffer-write-string.js n=1000000 len=2048 args='' encoding='utf16le'         ***    -12.57 %       ±6.85%  ±9.16% ±12.01%
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Jun 24, 2022

Copy link
Copy Markdown
Member

externally provided ArrayBuffer

How common is it in addons?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Jun 24, 2022

Copy link
Copy Markdown
Member

It's a tradeoff we've decided to make; I'm writing up our reasoning for it currently, will link when ready.

I wonder if there’s a programmatic way to inform addon authors of this; this has a pretty big effect, I assume.

Practically speaking, are you using Node’s ArrayBufferAllocator? If you don’t/if you stop using it, the problem solved by this particular PR should go away altogether, right?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nornagon

nornagon commented Jun 27, 2022

Copy link
Copy Markdown
Contributor Author

I'm closing this as the performance implications here are larger than I anticipated. This will still need to change in order to be compatible with V8 sandboxed pointers, but I'll take a different approach in a new PR.

As for the questions about impacts of enabling this in Electron, I don't think this is the appropriate place to dig into those, so I won't respond here. There will be a document soon with more details :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nornagon nornagon closed this Jun 27, 2022
@nornagon
nornagon deleted the sandbox-compat-zerofill branch June 27, 2022 21:34
@lovell lovell mentioned this pull request Sep 25, 2022
Enhancement: compatibility with Electron 21 will require copying all memory Buffers, will have performance cost lovell/sharp#3384
Closed
3 tasks done
@Nantris

Nantris commented Oct 1, 2022

Copy link
Copy Markdown

@nornagon are there any more details on the alternative approach that was taken? The blog post appears to indicate that the V8 Memory Cage should increase performance:

This feature has performance and security benefits

Are the performance benefits of the pointer compression greater than the performance degradations caused by the changes it required to enable?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Oct 2, 2022

Copy link
Copy Markdown
Member

@slapbox

are there any more details on the alternative approach that was taken?

#43594

Nantris reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@nornagon @nodejs-github-bot @bnoordhuis @joyeecheung @addaleax @RaisinTen @Nantris
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.