Skip to content
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

chore: enable v8_enable_private_mapping_fork_optimization by default #39253

Merged
merged 2 commits into from Aug 28, 2023

Conversation

deepak1556
Copy link
Member

@deepak1556 deepak1556 commented Jul 27, 2023

Description of Change

Benchmark test https://gist.github.com/deepak1556/4a585f987c634feae28232b63a5eb0e8

There is not much impact for the chromium child processes since they get forked from zygote process which does not get impacted by the V8 heap in the main process, so most of the gain with this change are for processes forked with child_process api which see an 8-9x improvement in the above test for a 600MB heap.

You can also disable zygote for comparison purpose --no-zygote --no-sandbox and the above test shows a 7x difference with the change. But this is not the most common case in real world as zygote is not disabled unless user decides to disable sandbox for the renderer process.

Release Notes

Notes: Improve fork/execve performance for child_process api on linux

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jul 27, 2023
@deepak1556 deepak1556 added semver/major incompatible API changes no-backport and removed new-pr 🌱 PR opened in the last 24 hours labels Jul 27, 2023
@electron-cation electron-cation bot added api-review/requested 🗳 new-pr 🌱 PR opened in the last 24 hours labels Jul 27, 2023
@bpasero
Copy link
Contributor

bpasero commented Jul 27, 2023

I think this also requires the change from https://chromium-review.googlesource.com/c/v8/v8/+/4602858 to be backported right? Or will that come in automatically in the Electron betas?

@deepak1556
Copy link
Member Author

The V8 change landed in Chromium 117 and Electron main branch is currently tracking Chromium 118.

@deepak1556 deepak1556 marked this pull request as ready for review August 2, 2023 11:51
@deepak1556 deepak1556 requested a review from a team as a code owner August 2, 2023 11:51
Copy link
Member

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be set in build/args/all.gn instead of adding a patch?

@deepak1556
Copy link
Member Author

@zcbenz is there a way to use OS specific conditions in all.gn ? The variables get defined in https://source.chromium.org/chromium/chromium/src/+/main:build/config/BUILDCONFIG.gn which gets loaded after all.gn and if I do something like v8_enable_private_mapping_fork_optimization = host_os == "linux" then I get

ERROR at build arg file (use "gn args <out_dir>" to edit):2:12: Undefined identifier host_os
v8_enable_private_mapping_fork_optimization = host_os == "linux"

@zcbenz
Copy link
Member

zcbenz commented Aug 4, 2023

There is no way to do so, I think we can:

  1. Always set the flag to true.
  2. Patch V8 so the flag is ignored on non-linux.

While there is no set rule on this, but for most build flags setting them do not break builds on unsuppoerted platforms. I think this is something we can upstream.

Copy link
Contributor

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepak1556
Copy link
Member Author

Always set the flag to true.

I think we can go this route, on macOS we use posix_spawn both in Node.js and Chromium to spawn child process and it already ignores copying the MAP_JIT locations, so this change should be a no-op.

@jkleinsc this is more of a feature flag change so would be better to keep it in build/config, IMO build time changes should be restricted to compiler related settings and not hide feature changes.

@deepak1556 deepak1556 changed the title chore: enable v8_enable_private_mapping_fork_optimization by default on linux chore: enable v8_enable_private_mapping_fork_optimization by default Aug 4, 2023
@zcbenz
Copy link
Member

zcbenz commented Aug 4, 2023

Build fails on mac.

@deepak1556 deepak1556 marked this pull request as draft August 4, 2023 11:55
@deepak1556
Copy link
Member Author

There is no MADV_DONTFORK defined in <sdk>/usr/include/sys/mman.h, will fix the failure in upstream.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Aug 9, 2023
@deepak1556
Copy link
Member Author

@deepak1556 deepak1556 marked this pull request as ready for review August 19, 2023 12:03
@deepak1556
Copy link
Member Author

deepak1556 commented Aug 25, 2023

Friendly ping for review @electron/wg-api

Copy link
Member

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

Copy link
Contributor

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@jkleinsc jkleinsc merged commit b5997a0 into main Aug 28, 2023
16 checks passed
@jkleinsc jkleinsc deleted the robo/speedup_fork_linux branch August 28, 2023 14:16
@release-clerk
Copy link

release-clerk bot commented Aug 28, 2023

Release Notes Persisted

Improved fork() and execve() performance for child_process API on Linux.

MrHuangJser pushed a commit to MrHuangJser/electron that referenced this pull request Dec 11, 2023
…lectron#39253)

* chore: enable v8_enable_private_mapping_fork_optimization by default

* chore: cherry-pick 292a4a6 from v8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants