garris/BackstopJS

Playwright 4x possible performance improvement

Closed this issue · 0 comments

Versions:
backstopjs@6.0.4
└── playwright@1.21.1

Firstly a big thank you to @FrostyShosty for your incredibly awesome PR for the playwright integration! We've just migrated and it works amazingly well and we've managed to ditch a load of nasty Puppeteer hacks for our environment so thank your for that. 🙏

Unfortunately it is noticeably slower than the standard puppeteer engine (probably 2x slower); this is not entirely unexpected as it looks like playwright is slower than puppeteer for some situations regardless.

Looking at the code (runPlaywright.js) and having used playwright in a .Net setting previously one thing that can massively improve performance is to share the 'browser' instance across the tests and use an instance of browserContext for isolating the tests. Currently line 73 creates a new browser instance for every scenario which is quite expensive and then a new context is created, if we can keep the context but avoid creating the browser instance each time then we should get some performance improvements.

From https://playwright.dev/docs/browser-contexts
image

A simple hack to my node_modules\backstopjs\core\util\runPlaywright.js local file to move the browser instance to the outer scope and only create it on the first call (not recommended but good for illustrative purposes!) reduces my test run of of 104 scenarios across 6 different viewports (624 in total) from 40 minutes to under 7 minutes(!).

e.g.
image

This obviously has it share of problems... notably that browser instance needs to be .close() once all of the tests have completed and I don't believe there's an easy way to hook into that. I'm not familiar with the backstopjs codebase as it stands so logging this now for awareness and will revisit to do some more digging.