Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Slower Laravel Package

halilcosdu/laravel-slower

Detect and log slow Laravel database queries, then get AI-powered suggestions for indexes and query improvements. Configurable thresholds, can run with or without AI, and supports Laravel 10–13 on PHP 8.2+.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Enhanced Observability with Fingerprints: The introduction of query fingerprints (parameterized SQL normalization) transforms raw query logging into a grouped, deduped view, reducing noise and enabling trend analysis. This aligns with modern observability stacks (e.g., OpenTelemetry) where semantic grouping of traces/metrics is critical. The Grouped toggle in the dashboard mirrors tools like Honeycomb or Datadog’s service maps, making it easier to triage performance clusters.

    • Trade-off: Fingerprinting adds a lexer-style normalization pass (~5–10ms per slow query), but this is offset by reduced storage/query overhead in the grouped view.
  • Origin Context for Root-Cause Analysis: Capturing HTTP routes, queue jobs, or CLI origins + code backtraces (opt-in) bridges the gap between slow queries and their business context. This is a game-changer for debugging in microservices or monoliths with shared databases, where a slow User::where(...) might originate from CheckoutController@create or a SendWelcomeEmail job.

    • Privacy Note: The authenticated user ID is opt-in and never sent to the LLM, addressing compliance concerns (e.g., GDPR) while still enabling user-specific query analysis.
  • Production-Grade Safeguards:

    • Sampling (capture.sample_rate): Mitigates storage bloat in high-volume apps (e.g., 1% sampling for 10K QPS → ~100 slow queries/day).
    • Circuit Breaker: Prevents storage failures from cascading (e.g., DB timeouts during peak loads).
    • Self-Capture Guard: Ensures the package itself doesn’t log its own queries, avoiding infinite loops.
  • AI-Augmented Workflow Improvements:

    • Structured Payloads: The ai_payload config ensures only parameterized SQL + schema + origin are sent to the LLM, eliminating raw SQL/binding leaks. This is a critical fix for security-sensitive apps (e.g., financial systems).
    • Events-Driven Extensibility: SlowQueryCaptured/SlowQueryFirstSeen events enable custom alerting (e.g., Slack pager for new slow queries) without modifying core logic.
  • Queued Analysis for Scalability: Backgrounding slower:analyze via Laravel Queues decouples analysis from request processing, reducing latency spikes during peak hours. This is essential for high-traffic apps (e.g., e-commerce during Black Friday).

Integration Feasibility

  • Backward Compatibility:

    • No Breaking Changes: Existing config/APIs remain untouched. The migration is additive (new tables/columns only).
    • Synchronous Analysis Still Default: Zero worker setup required for simple use cases; queued analysis is opt-in.
  • New Dependency Risks:

    • Laravel Queues: Queued analysis requires a queue driver (e.g., Redis, database). Teams using database queues should monitor slower_analysis_jobs table growth.
    • PHP 8.4: Minimum version bump (from 8.2) may require runtime upgrades for legacy systems. However, this aligns with Laravel’s LTS support (11–13).
  • Storage Overhead:

    • Fingerprint Backfill: slower:fingerprint is idempotent and chunked, but may take hours for large slow_log tables (e.g., 1M+ rows). Schedule during off-peak hours.
    • Origin Backtrace: Adds ~100–200B per row (file:line + origin context). For 1K slow queries/day, this is ~100KB–200KB/month—negligible for most apps.
  • AI Payload Redaction:

    • Security Critical: Misconfigured PayloadRedactor now throws instead of leaking data. This requires upfront validation of the redactor’s shouldRedact() logic.
    • Performance Impact: Redaction adds ~1–2ms per query, but this is one-time during payload generation.

Technical Risk

Risk Area Severity Mitigation Strategy
Fingerprint Normalization Errors Medium False splits (query variants treated as identical) are documented as a trade-off. Use slower:fingerprint --dry-run to validate grouping logic.
Queued Analysis Failures Medium Jobs drop cleanly if records are pruned. Monitor failed_jobs table for retries.
Backtrace Privacy High Disable with capture.backtrace: false; audit DEBUG_BACKTRACE_IGNORE_ARGS for PII.
Storage Bloat Low Use capture.sample_rate and schedule slower:clean aggressively.
PHP 8.4 Upgrade Costs Medium Test in staging first; leverage Laravel’s upgrade guides.
Event Listener Failures Low Throwing listeners are non-blocking; circuit breaker ensures query logging continues.

Key Questions for Stakeholders

  1. Observability Strategy:

    • Should the Grouped view replace or complement existing APM tools (e.g., New Relic)? How will fingerprints integrate with your SLO/SLI definitions?
    • For microservices, should origin context include service names (e.g., api-gateway, order-service)? This requires customizing the OriginResolver.
  2. Privacy and Compliance:

    • Is capture.backtrace: true acceptable for your stack? If not, how will you map slow queries to business flows without code context?
    • Should authenticated user IDs be captured (opt-in) for tenant-aware multi-tenancy setups?
  3. Operational Trade-offs:

    • Should slower:analyze run synchronously (default) or queued? Queued analysis reduces latency but adds queue infrastructure.
    • What’s the target sample rate (capture.sample_rate) for production? Default (1.0) may be too high for high-volume endpoints.
  4. Integration with CI/CD:

    • Should SlowQueryFirstSeen events block deploys if critical queries exceed thresholds? Example:
      event(new SlowQueryFirstSeen($query))
          ->then(fn() => throw new \RuntimeException("Critical query detected!"));
      
    • How will fingerprint changes affect canary releases? Fingerprints are versioned, but A/B tests may need explicit query whitelisting.
  5. Cost vs. Insight:

    • With queued analysis, how will you balance AI recommendation costs against the value of origin-aware insights?
    • Should ai_payload exclude certain schemas (e.g., analytics.*) to reduce token usage?

Integration Approach

Stack Fit

  • Laravel Ecosystem:

    • Queues: Queued analysis integrates with Laravel’s queue system (supports all drivers: database, Redis, etc.).
    • Events: SlowQueryCaptured/SlowQueryFirstSeen fit Laravel’s event ecosystem (e.g., Illuminate\Events\Dispatcher).
    • Testing: Playwright-tested UI ensures compatibility with Laravel’s Blade/Dusk stack.
    • Debugging: Backtrace integration works with Laravel’s debugbar and telescope.
  • Database Compatibility:

    • Fingerprinting: Works with PostgreSQL, MySQL, SQLite (via Laravel’s query builder). Custom drivers may need EXPLAIN syntax adjustments.
    • Storage: New slow_query_fingerprints table requires indexes on fingerprint and connection for grouped queries. Test with your DB’s collation (e.g., utf8mb4_unicode_ci for MySQL).
  • Third-Party Tools:

    • OpenAI: ai_payload redactor ensures compatibility with Laravel’s OpenAI SDK (v4+).
    • FilamentPHP: Future plugin support is implied but not yet released. Current CLI/UI remains standalone.
    • APM Tools: Expose grouped queries via Prometheus metrics (e.g., slow_query_count_by_fingerprint) for Grafana dashboards.

Migration Path

  1. Pre-Migration Audit:

    • Review existing slow_log table size. For >100K rows, backfill fingerprints in chunks:
      php artisan slower:fingerprint --chunk=1000
      
    • Validate PayloadRedactor config:
      'ai_payload' => [
          'redactor' => \HalilCosdu\Slower\Redactors\DefaultRedactor::class,
          'should_redact' => fn($query) => !str_starts_with($query->schema, 'public'),
      ],
      
  2. Installation:

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor