playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] Channel chrome on M1 chip performance degradation

Open vladyslavlopa opened this issue 3 years ago • 10 comments

Context:

  • Playwright Version: 1.25.0
  • Operating System: Mac M1 pro
  • Node.js version: 14.6
  • Browser: Chrome
  • Extra: channel chrome

Code Snippet

import { test, expect } from '@playwright/test';
  test('login to homepage with Email', async ({ page, baseURL }) => {
  await page.goto('https://google.com/')
  });  


Playwright project config for chrome channel

 {
      name: 'chromium',
      use: {
        channel: 'chrome',
        ...devices['Desktop Chrome'],
      },
    },

Describe the bug

When tests are run with channel chrome rendering speed is severely affected. Chrome under tests tries to eat all the cpu and RAM available. The easiest way to experience it is to make a debug breakpoint and open chrome in headed mode and try to use it. (pop inspect, navigate to another page) There are no issues with the default chromium channel. Chrome channel is used in my case to have FFmpeg codecs included.

vladyslavlopa avatar Sep 08 '22 12:09 vladyslavlopa

@vladyslavlopa I just tried this on M1, and there is no performance difference between chrome and chromium when I page.goto('https://google.com/'). Perhaps something's different in your setup?

You can try recording performance trace in Chrome Developer Tools in both browsers and compare them, or attach them here and we can take a look. Other than that, we should be able to reproduce the issue in order to fix it.

dgozman avatar Sep 08 '22 20:09 dgozman

https://user-images.githubusercontent.com/6050427/189523230-664f3ada-a907-4042-8350-82c800c53773.mov

Video from chromium: Everything seems to be flying as it should. opening up inspect almost in an instant and page refresh does not load CPU that much.

Unfortunately, I could not get a full screen capture with less 10 mb here for chrome (not sure what's the difference). Every time I refresh the page it loads CPU to 100%. This is the problem not only for the rendering itself. But seems like the whole chrome is freezing. Opening Inspect for the page is taking ages. Video for Chrome channel:

https://user-images.githubusercontent.com/6050427/189523350-5d99d210-155c-4219-9c0d-137bd62ab174.mov Screenshot from refreshing google page with performance insights (it spikes CPU to 100% every-time page is loaded) Screenshot 2022-09-11 at 12 42 18

I have performance insights log here from Chrome channel. But, it seems that functionality is not available in chromium, so nothing really to compare against ChromePerformanceTrace.gz

vladyslavlopa avatar Sep 11 '22 10:09 vladyslavlopa

We are also noticing some issues when channel is specified (running scripts on Apple M1 chip). on an average, a single test run takes about 9 seconds when No channel is specified. when we specify a channel (say chrome), page load times increase tremendously,overall script execution time is about 35 secs. there is a vivid difference.

harir5 avatar Sep 12 '22 05:09 harir5

Could you run the following command in the terminal and provide us the output? It will show if you are running the arm and amd version of Google Chrome:

file "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

Also it might be about Enterprise policies. Are you in a corporate/managed environment? Could you go to chrome://policy with your Google Chrome and see if there are some entries?

mxschmitt avatar Sep 13 '22 08:09 mxschmitt

result of execution

/Applications/Google Chrome.app/Contents/MacOS/Google Chrome: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64
- Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64
- Mach-O 64-bit executable arm64]
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome (for architecture x86_64):	Mach-O 64-bit executable x86_64
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome (for architecture arm64):	Mach-O 64-bit executable arm64

There are no policies set for the chrome Screenshot 2022-09-13 at 13 12 19

vladyslavlopa avatar Sep 13 '22 11:09 vladyslavlopa

So yeah this output looks good, it's a good Google Chrome executable (universal binary) and there are no policies configured.

Are you using Google Chrome as your main browser? Would be useful if you could try to reproduce it without Playwright. This means opening the browser, navigating to websites etc. if this is also very slow, then its not a Playwright bug and I'd redirect you to crbug.com

mxschmitt avatar Sep 13 '22 11:09 mxschmitt

I am using it as a default browser. I have not noticed any issues in the last 2 weeks with it. It only becomes an issue when using it as a browser under test from Playwright

vladyslavlopa avatar Sep 13 '22 11:09 vladyslavlopa

@mxschmitt - i too am seeing the same thing in my macbook as well. When i use it in a playwright test, i see a sudden increase in execution time.

harir5 avatar Sep 16 '22 02:09 harir5

@harir5 are you also on M1?

mxschmitt avatar Sep 16 '22 09:09 mxschmitt

@mxschmitt - i use an older macbook, but my colleagues use the M1. they are seeing this issue.

harir5 avatar Sep 16 '22 09:09 harir5

I get the same issue when I upgraded to a Mac with M1 chip. When I run Chrome from Applications it uses the arm64 version of Chrome. But when I run Playwright it uses the intel Chrome.

The tests run fine for my colleagues that have M1 chip devices. I did use the option to copy data from my old intel Mac to the new M1 Chip. I wonder if there is some setting that was copied from my old Intel Mac that is causing Playwright to use the Intel Chrome.

I filed this related issue: https://github.com/microsoft/playwright/issues/19602

mrwwalmsley avatar Dec 20 '22 18:12 mrwwalmsley

I'm also seeing the same issue while switching to an M1 laptop.

bdav avatar Feb 17 '23 19:02 bdav

Very degraded performance at Google Chrome 112.0.5615.49.

tassoevan avatar Apr 14 '23 19:04 tassoevan

Just hit this problem, you need to un-check Open using Rosetta on your Terminal (or whatever shell), and restart your machine: Screenshot 2023-07-07 at 2 13 09 PM

I'm assuming Chrome when launched via Playwright (which is launched via Terminal) is inheriting the arch somehow. You can check this by hitting About Google Chrome and checking the arch in the parenthesis: Screenshot 2023-07-07 at 2 18 46 PM

If you pause your Playwright session and it shows x86_64 translated, then it is running in the wrong arch.

wburgess-around avatar Jul 07 '23 18:07 wburgess-around

If you are using terminal to run your test cases. Just add prefix to your execution command arch -arm64.

It works wonders!!

Example: arch -arm64 npx playwright test

AbhishekPalani avatar Aug 27 '23 15:08 AbhishekPalani

I'm still running into this issue. Would really appreciate any suggestions on how to force playwright to open the arm64 version of chrome.

Context:

Playwright Version: 1.40.0 Operating System: Mac M1 pro Python version: 3.10.6 Browser: Chrome Extra: channel chrome

Tests I ran:

  • Neither Iterm2 or Chrome have "Open using Rosetta" checked
  • When I run "sysctl -n sysctl.proc_translated" I get 0
  • When I run playwright and open the browser to chrome://version it shows it's x86 (see attached image). When I check chrome://version I use day-to-day (i.e. not opened by Playwright) it shows arm64.
  • I have no chrome policies set
  • When I run: file "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" /Applications/Google Chrome.app/Contents/MacOS/Google Chrome: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64] /Applications/Google Chrome.app/Contents/MacOS/Google Chrome (for architecture x86_64): Mach-O 64-bit executable x86_64 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome (for architecture arm64): Mach-O 64-bit executable arm64
Screenshot 2024-01-17 at 5 09 24 PM

DavidPatterson-Cole avatar Jan 17 '24 22:01 DavidPatterson-Cole

I faced the same issue. Google Chrome was getting launched in the x86_64 translated version instead of the arm version which was slowing down the entire browser and using up a lot of system resources. I was running the Playwright commands on a non-rosetta-enabled terminal. (To check if you have rosetta enabled you can type arch in your terminal. If it returns arm64 then you're not using rosetta. If it returns i386 then it is using rosetta.)

The reason why Chrome is launching in the x86 translated build is probably because the node version you're using must be an x86 version. To confirm this you can use the os library provided by NodeJS. Add this code in your playwright.config.(ts/js) file:

// playwright.config.ts

import os from "os"

console.log(`Architecture: ${os.arch()}`);

// Rest of your config file..

Now when you run your Playwright tests in a non-rosetta-enabled terminal, if you see Architecture: x64 then that means you have the x86 version of node installed on your system. This might have been caused because you installed node in a rosetta-enabled terminal. To solve this issue is as simple as to uninstall and reinstall your current version of node from a non-rosetta enabled terminal. If you're using nvm then you can follow the steps below.

arch # Make sure this is returning arm64. Else exit out of the terminal, disable rosetta for it and restart it.
node -v # Note down the current node version for reinstalling the same version
nvm deactivate # To make sure node doesn't throw an error when you try to uninstall the default node version. In my case it was 18.12.1
nvm uninstall 18.12.1 # Uninstall the node version you're using
nvm install 18.12.1
nvm alias default 18.12.1
node -v # Executing this command should give the same node version again

It's important to note that executing the commands above might affect your package managers like yarn if you have them installed. In that is the case you just have to reinstall them.

Now you can go to your playwright test folder and execute this command to reinstall all the packages.

rm -rf node_modules  && rm -rf yarn.lock && yarn install
# Or
rm -rf node_modules  && rm -rf package.lock && npm install

Once this is done you should be able to open Chrome in the arm64 version in the Playwright tests and the tests should execute much more smoothly.

VarunSriram99 avatar Feb 28 '24 18:02 VarunSriram99