Skip to content

Memory improvements by only returning the needed JSON output via NodeJS#63

Merged
freekmurze merged 5 commits intospatie:mainfrom
mattiasgeniar:main
Oct 3, 2025
Merged

Memory improvements by only returning the needed JSON output via NodeJS#63
freekmurze merged 5 commits intospatie:mainfrom
mattiasgeniar:main

Conversation

@mattiasgeniar
Copy link
Copy Markdown
Contributor

@mattiasgeniar mattiasgeniar commented Oct 3, 2025

The NodeJS wrapper returned the entire JSON output of the Lighthouse check, which contains 3 major blocks:

  • lhr
  • artifacts
  • report

We only need the HTML & JSON output that is in report and any runtime errors in lhr, the rest currently isn't used. This PR filters only the necessary fields in NodeJS and prevents PHP from re-encoding the JSON string, which in extreme cases causes out-of-memory issues.

This PR remains simple and if there's ever a need for more data out of the Lighthouse package, it should be simple to extend the NodeJS output.

Peak memory usage results from testing:

URL Before After Change Percentage
https://ohdear.app 1221MB 13.2MB -98.92%
https://example.com 17MB 9MB -47.06%
https://spatie.be 63MB 10.1MB -83.97%
-Redacted- 415MB 12.39MB -97.01%

Even in simple HTML examples the gains are ~50%, in edge-cases (ie complex sites) it can be as high is 90%+.

@freekmurze
Copy link
Copy Markdown
Member

freekmurze commented Oct 3, 2025

Great work, I didn't realize these reports were so big.

@freekmurze freekmurze merged commit 1a55598 into spatie:main Oct 3, 2025
4 checks passed
@freekmurze
Copy link
Copy Markdown
Member

Thanks!

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.

2 participants