Skip to content

[12.x] Avoid unnecessary filtering when no callback is provided #56225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

AhmedAlaa4611
Copy link
Contributor

Description

This PR refactors the recorded() method in the HTTP client to avoid an unnecessary call to filter() when no callback is provided.

Currently, when $callback is null, the method creates a default closure that always returns true, then filters the entire collection; effectively doing nothing but still iterating over the data.

This change short-circuits that path by simply returning the collection directly when no filtering is needed, resulting in slightly better performance and improved clarity, especially when dealing with large numbers of recorded request/response pairs.

@taylorotwell taylorotwell merged commit d6ecb78 into laravel:12.x Jul 7, 2025
62 checks passed
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