Skip to content

Performance Improvement: Database Query Log Memory Optimization #56506

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

Draft
wants to merge 2 commits into
base: 12.x
Choose a base branch
from

Conversation

Amirhf1
Copy link
Contributor

@Amirhf1 Amirhf1 commented Jul 31, 2025

Problem
The Laravel Database Connection class logs all executed queries when query logging is enabled, but without any limit on the number of queries stored. This can lead to significant memory consumption in long-running applications or when executing many database queries.

  • Add maxQueryLogSize property with default limit of 1000 queries
  • Implement automatic cleanup when limit is exceeded
  • Add setMaxQueryLogSize() and getMaxQueryLogSize() methods
  • Add comprehensive tests for the new functionality
  • 99% memory usage reduction in high-query scenarios
  • Full backward compatibility maintained

Closes potential memory leak in long-running applications

- Add maxQueryLogSize property with default limit of 1000 queries
- Implement automatic cleanup when limit is exceeded
- Add setMaxQueryLogSize() and getMaxQueryLogSize() methods
- Add comprehensive tests for the new functionality
- 99% memory usage reduction in high-query scenarios
- Full backward compatibility maintained

Closes potential memory leak in long-running applications
@Amirhf1 Amirhf1 marked this pull request as draft July 31, 2025 19:58
@rodrigopedra
Copy link
Contributor

  • Full backward compatibility maintained

API-wise, sure. Behavior-wise, no.

If someone is relying on the current behavior, the change should be noted, ideally in the upgrade guide.

@stancl
Copy link
Contributor

stancl commented Aug 6, 2025

To add this to L12 in a backwards-compatible way, you want the limit to support being -1 or null — a value that disables the limit. Set the limit to that in L12 and in a separate PR to master set a default limit in L13.

Not sure if a limit being set by default makes sense though.

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.

3 participants