paparazzi icon indicating copy to clipboard operation
paparazzi copied to clipboard

OutOfMemory when doing a lot of screenshoting in a single test run

Open hrach opened this issue 1 year ago • 2 comments

Description We get OOM when there is a lot of screenshoting in a single test run. We have our "helper" aka

@Test
fun testSomething() {
  snapshot { TestedUi() }
}

That internally iterates over many configurations and screenshots the composable lamba with multiple device confnigurations.

Something like

for (device in ComplexScreenshotDevices) {
  for (locale in ComplexScreenshotLocales) {
    makeSnapshot(content)
  }
}

There are two devices and about 15 languages. Adding a third device easily triggers the OOM for us.

makeSnapshot is basically

Locale.setDefault(locale)
paparazzi.unsafeUpdateConfig(
  config.copy(
    locale = locale.language,
    softButtons = false,
  ),
)
paparazzi.snapshot(name, content)

When we do too much, it OOMs - both locally or in CI.

   java.lang.OutOfMemoryError: Java heap space
        at java.desktop/java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
        at java.desktop/java.awt.image.Raster.createPackedRaster(Raster.java:539)
        at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
        at java.desktop/java.awt.image.BufferedImage.<init>(BufferedImage.java:333)
        at app.cash.paparazzi.internal.ImageUtils.scale(ImageUtils.kt:286)
        at app.cash.paparazzi.Paparazzi.scaleImage(Paparazzi.kt:413)
        at app.cash.paparazzi.Paparazzi.access$scaleImage(Paparazzi.kt:83)
        at app.cash.paparazzi.Paparazzi$takeSnapshots$1$2.invoke(Paparazzi.kt:326)
        at app.cash.paparazzi.Paparazzi$takeSnapshots$1$2.invoke(Paparazzi.kt:313)
        at app.cash.paparazzi.Paparazzi.withTime(Paparazzi.kt:361)
        at app.cash.paparazzi.Paparazzi.takeSnapshots(Paparazzi.kt:313)
        at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:207)
        at app.cash.paparazzi.Paparazzi.snapshot$default(Paparazzi.kt:206)
        at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:202)
        at xxx.BaseScreenshotTest.makeSnapshot(BaseScreenshotTest.kt:112)

hrach avatar Sep 15 '23 12:09 hrach

I think it's a duplicate of https://github.com/cashapp/paparazzi/issues/915

TWiStErRob avatar Sep 15 '23 12:09 TWiStErRob

Any sort of status on this? We are still running out of memory and the ticket that was supposed to be a duplicate of this is closed, but that seems to be because it's fixed by Google, but there still doesn't seem to be a distribution with that version Google fixed it in included.

I tried to implement the work around mentioned, but it is missing some details.

Thanks. Kenny

KennyGoers avatar Jan 16 '24 16:01 KennyGoers