cashapp / paparazzi

Render your Android screens without a physical device or emulator
https://cashapp.github.io/paparazzi/
Apache License 2.0
2.31k stars 215 forks source link

First paparazzi test in module takes too long time #1662

Open zhkvdm opened 3 weeks ago

zhkvdm commented 3 weeks ago

Description We have multimodule android project. Every module contains some different paparazzi tests. First launchable test method in first test class always takes too long time. It runs in ~20s. The next tests takes 0.5 - 2s. The same in the different modules. What's the cause of the freeze? How to speed up tests launch?

Steps to Reproduce Run paparazzi tests with multiple test methods for whole module. Use gradle task ./gradlew :feature:verifyPaparazziDebug

Additional information:

Screenshots Test reports: 1 Image Image

2 Image Image

geoff-powell commented 3 weeks ago

Do you mind providing a sample project that reproduces the issue?

zhkvdm commented 3 weeks ago

Do you mind providing a sample project that reproduces the issue?

I can't share this project, it's prohibited. But I can try to reproduce this issue at sample project

jrodbx commented 3 weeks ago

First launchable test method in first test class always takes too long time. It runs in ~20s. The next tests takes 0.5 - 2s. The same in the different modules. What's the cause of the freeze? How to speed up tests launch?

The first test bootstraps Layoutlib via Bridge.init and statically caches it for subsequent runs, which explain why you notice a drop after the first test.

However, ~20s is high and I've never seen this before. I suspect you may just be running the tests with a conservative heap size; if so, bumping the max heap size should be enough to fix this.

zhkvdm commented 3 weeks ago

First launchable test method in first test class always takes too long time. It runs in ~20s. The next tests takes 0.5 - 2s. The same in the different modules. What's the cause of the freeze? How to speed up tests launch?

The first test bootstraps Layoutlib via Bridge.init and statically caches it for subsequent runs, which explain why you notice a drop after the first test.

However, ~20s is high and I've never seen this before. I suspect you may just be running the tests with a conservative heap size; if so, bumping the max heap size should be enough to fix this.

Okay, thanks for reply. Is it possible to cache and share Layoutlib between all modules? Now each module init Layoutlib when running tests.

jrodbx commented 2 weeks ago

Is it possible to cache and share Layoutlib between all modules?

This is a Gradle design issue. Each module has its own test task, which I believe runs in its own process via the test runner. If I'm understanding this correctly, then the answer to your question would be "no".

What's your current CI heap size? Have you tried increasing it?

zhkvdm commented 2 weeks ago

Is it possible to cache and share Layoutlib between all modules?

This is a Gradle design issue. Each module has its own test task, which I believe runs in its own process via the test runner. If I'm understanding this correctly, then the answer to your question would be "no".

What's your current CI heap size? Have you tried increasing it?

We run tests in docker container with params --memory=42g --cpus="8" Xmx25

zhkvdm commented 1 week ago

I have tried an android screenshot testing (https://developer.android.com/studio/preview/compose-screenshot-testing). It works faster than paparazzi, but it should use the same mechanics, I think. Image

zhkvdm commented 1 week ago

I have created a new empty project with 2 screens and 6 paparazzi tests. The test takes 3s on initialization. Is it ok? Image Image

nick2525 commented 3 days ago

@jrodbx I posted a proposal to gradle https://github.com/gradle/gradle/issues/31332 so that there is a way to bypass this restriction

nick2525 commented 3 days ago

Gradle recommend to use build services https://docs.gradle.org/current/userguide/build_services.html