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

cli: throw error if running x64 node on mac arm64 #14288

Merged
merged 2 commits into from
Aug 15, 2022
Merged

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Aug 13, 2022

https://docs.google.com/document/d/1hEt6q0BlZ1c50UNhm9ejXNKLvcOX8pStspCY6hAKwDI/edit# (can just read the most recent update, pasted below).

The issue was my Node was built for x64 and when you spawn a process from x64, apparently Apple just assumes that it needs to be translated so it uses its Rosetta tech to do that. In chrome://version I see x86_64 translated when that happens, and get ~10x perf regressions.

image


This PR fixes (well, at least warns about) yarn smoke perf-preload on my machine.

For pretty much any CLI invocation – (spawning chrome from my x64 Node install...apparently 14.20 is only distributed as x64 via nvm. arm64 only became a thing sometime in 15.x) – Chrome would get "translated" to some weird hybrid x64->arm64 binary (even tho the Chrome install is already arm64?!). That resulted in ~10x perf regressions all throughout Chrome. Any test that was perf-sensitive ... like perf-preload ... was bound to fail.

Initially I sought to grab the arch from Browser.getVersion, but it isn't exposed there. And what chrome://version uses is not easily exposable to CDP. So let's just detect the case where we know Rosetta would kick in - from an x64 node binary running on mac arm64.

@connorjclark connorjclark requested a review from a team as a code owner August 13, 2022 00:11
@connorjclark connorjclark requested review from brendankenny and removed request for a team August 13, 2022 00:11
@connorjclark connorjclark changed the title cli: throw error if running x64 node on mac arm64 device cli: throw error if running x64 node on mac arm64 Aug 13, 2022
cli/run.js Outdated Show resolved Hide resolved
@avidrissman
Copy link

Hi! Chrome dev here from the filed https://crbug.com/1305353.

Your analysis is mostly correct.

Chrome ships with both x64 and arm64 (“universal”) so that we can offer one download for users that will work natively with whatever Mac they have. If you run an x64 binary on an Arm Mac under Rosetta and then it spawn subprocesses, macOS will indeed cause all the subprocesses to also be run under Rosetta.

Chrome would get "translated" to some weird hybrid x64->arm64 binary (even tho the Chrome install is already arm64?!)

No hybridization, just Rosetta doing its thing on the x64 version inside the universal Chrome binary.

Thank you for bringing this to our attention. The correct thing to do is what you have done, to avoid Rosetta entirely by only running arm64 binaries on your arm64 Mac. In the Chromium bug mentioned earlier, we will be doing more to enforce this on Chrome’s end. Running Chrome under Rosetta is not a tested configuration. We thought it was just slow, but if it’s also spewing errors (as you note), we should disallow it if possible.

Thank you for reaching out!

@connorjclark
Copy link
Collaborator Author

Awesome, thanks @avidrissman!

@connorjclark
Copy link
Collaborator Author

even tho the Chrome install is already arm64?!

btw this is because Chrome on mac ships as a universal binary, thus it has both arm and x64 binaries. So launching a child process from an x64 process will grab the x64, even if on arm64 and an arm64 implementation is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants