perf(http): lazy load DomCrawler instance on demand in Response - #294
Open
alex-kassel wants to merge 6 commits into
Open
perf(http): lazy load DomCrawler instance on demand in Response#294alex-kassel wants to merge 6 commits into
alex-kassel wants to merge 6 commits into
Conversation
added 5 commits
August 11, 2026 22:03
…e, and lazy loading assertion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Optimization
This PR refactors
RoachPHP\Http\Responseto lazy-load theSymfony\Component\DomCrawler\Crawlerinstance on demand rather than eagerly instantiating it insideResponse::__construct().The Problem
Previously,
Response::__construct()eagerly instantiated a newSymfony\Component\DomCrawler\Crawlerfor every HTTP response. When crawling APIs or JSON endpoints returning large payloads (e.g. 2–10 MB JSON arrays),DomCrawlerparsed raw JSON as HTML DOM nodes, causing memory spikes of 100 MB – 150 MB+ and memory limit exhaustion.The Solution
Switch
$crawlerto a nullable property initialized lazily ingetCrawler():Crawlerparsing.$response->filter()or mixin methods triggersgetCrawler(), initializing theCrawlerdynamically.