-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Enhancement: compatibility with Electron 21 will require copying all memory Buffers, will have performance cost #3384
Comments
A "more secure" feature that "will crash at runtime" sounds like a bit of an oxymoron. The only workaround would be to take a copy of all memory before returning it to JS. This will affect Buffer and Stream-based output, as well as calls to Is there a way of querying the Electron runtime to determine if this "memory cage" feature is enabled, ideally via an ABI-stable |
yeah, I am really not impressed. Out of the 7 native modules I use, 6 will break from this change which to me makes it far from 'rare'. Yeah, performance is my second concern here too. Especially not wanting to penalise nodejs users because of electron. I havent looked yet, but from a skim of the original PR I dont see anything. To clarify, I don't personally need this yet (Im very bad at keeping electron updated). But I've spent the last couple of hours looking into this and things around this, and thought you could do with a heads up to expect 'bug' reports users about this |
I did a quick search of Node.js for previous discussion around a "memory cage" and the only result is a closed-and-not-merged PR that has some interesting observations about the performance impact. Electron patches its Node.js with what appears to be a similar change, so it's possible there'll be a performance impact on anyone using Buffers in Electron. https://github.com/electron/electron/blob/main/patches/node/support_v8_sandboxed_pointers.patch |
I just read the Electron 21 blog post and headed straight here and saw my fear confirmed.
I don't know of any direct way to query for this feature, but the Electron version could be queried at least? |
@lovell the implementation they actually went with can be found by following the link in this comment: nodejs/node#43537 (comment) - not sure if it's relevant, but in the interest of gathering the necessary data. |
I dont think that really teaches us anything. All I see there is changing some node internals to always use a different memory allocator, which is essentially what they have said we need to do in that blog post |
I see a related warning when using Electron 21:
As well, use of |
Please see nodejs/node#45181 for the required changes to Node.js itself and nodejs/node-addon-api#1227 for follow-up changes to the |
@arnhrwd That Buffer deprecation warning is not from sharp. |
@lovell , FYI nodejs/node#45181 has landed. |
@lovell In case you aren't following along, the upstream change has been released in node 19.1.0, but not any other versions of nodejs yet. And I don't think it is in any release of electron yet |
There's a work-in-progress branch for this at v8-memory-cage, which is dependent on Electron updating its various internal versions of Node.js to include the new |
When using the V8 memory cage, Buffers cannot be wrapped and then later freed via a callback. When the cage is detected via a throw, instead fall back to copying Buffer contents to V8 memory. This approach will be used by Electron 21+ and you should expect reduced performance and increased memory consumption/fragmentation.
Commit 584807b adds this and it will be part of v0.31.3. Please remember you'll need a version of Electron that provides the patched version of Node.js |
v0.31.3 now available with a workaround for the V8 memory cage. Please remember you'll need a future version of Electron that provides the patched version of Node.js to take advantage of this. https://github.com/electron/electron/search?q=09ae62b&type=issues |
Local 6.6+ uses Electron 21, which implements a new memory cage feature: https://www.electronjs.org/blog/v8-memory-cage The memory cage prevents Node.js modules such as sharp from working: lovell/sharp#3384 Sharp is used by Next.js to optimize images. The result is that Local produces a 502 when users create new sites using this blueprint, due to the optimized logo image in the header and in featured images. Using the `unoptimized` prop prevents this. The fix could be removed when Electron updates with the patched version of Node.js that allows sharp's workaround to function, and when Local has updated to that Electron version.
Adopts the latest version of the sharp library so that image resizing will work with the latest versions of Electron, once it updates with a fix for the memory cage issue. See lovell/sharp#3384. Replaces #103.
It worked fine after I downgraded to electron 19.1.8 |
Works smoothly after upgrade to Electron |
Based on the release notes, the following versions of Electron are all patched and should work with sharp v0.31.3+
|
This works around an Electron crash that occurs when creating thumbnails for very large images when using Canvas for resizing. * Add 'sharp' library * Bump electron minor version to deal with lovell/sharp#3384
This works around an Electron crash that occurs when creating thumbnails for very large images when using Canvas for resizing. * Add 'sharp' library * Bump electron minor version to deal with lovell/sharp#3384
This works around an Electron crash that occurs when creating thumbnails for very large images when using Canvas for resizing. * Add 'sharp' library * Bump electron minor version to deal with lovell/sharp#3384 fixup
@lovell just a question if my problem is related to this all new memory handling with electron + node. I have an electron app and everything runs wonderful with v23. but when using v24 i get random: PS: i found a possible root cause in another github issue/solution with a similar issues in my system is ubuntu 22.04, node 18, sharp 0.33, electron 24 (breaks), electron 23 (works) Thanks you very much - your support and project is amazing :) |
@KillerCodeMonkey I'm unsure which version "sharp 0.33" refers to, but the latest sharp v0.32.0 does not rely on the GSlice allocator at all, as it has been removed from the glib dependency, so I would guess this error is more likely to be from Electron. The |
thanks for the quick replay and you are right.. sorry for the typo, i meant sharp v0.32.0 |
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
npm install sharp
completes without error.node -e "require('sharp')"
completes without error.Are you using the latest version of sharp?
sharp
as reported bynpm view sharp dist-tags.latest
.What is the output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
?What are the steps to reproduce?
Run sharp with electron 21
What is the expected behaviour?
Sharp should be compatible
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
It is important to run the script through electron, and it has to be v21+
Please provide sample image(s) that help explain this problem
This is because of a change electron have made, which breaks compatability for some native modules https://www.electronjs.org/blog/v8-memory-cage
Electron 21 was released on the 27th September, and I have opened an issue to complain about their breakage of the guaranteed stable node-api that electron are doing here. electron/electron#35801
The text was updated successfully, but these errors were encountered: