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

Dic Service Benchmark Bundle Laravel Package

dawen/dic-service-benchmark-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require dawen/dic-service-benchmark-bundle
    

    No kernel registration is required—this is a zero-configuration package.

  2. First Run: Execute the bundled test directly via PHPUnit (disable coverage for faster results):

    ./vendor/bin/phpunit -c app vendor/dawen/dic-service-benchmark-bundle/Tests/DicServiceBenchmarkTest.php
    

    Outputs a list of registered services with their instantiation times.

  3. Threshold Check: The test fails if any service exceeds 50ms by default. Useful for performance regression detection.


Implementation Patterns

Workflows

  1. Performance Profiling:

    • Integrate into CI/CD pipelines to catch slow service instantiation early.
    • Example: Run post-commit or pre-deploy:
      ./vendor/bin/phpunit -c app --filter=DicServiceBenchmarkTest
      
  2. Ignoring Services:

    • Exclude non-critical services (e.g., debug tools) via phpunit.xml:
      <php>
          <var name="dic-service-benchmark-ignore" value="web_profiler.controller.router:my_ignored_service"/>
      </php>
      
    • Format: Colon-separated list of service IDs (supports wildcards? Not documented—verify).
  3. Custom Thresholds:

    • Override the default 50ms threshold by extending the test class:
      // tests/DicServiceBenchmarkCustomTest.php
      use Dawen\Bundle\DicServiceBenchmarkBundle\Tests\DicServiceBenchmarkTest;
      class CustomBenchmarkTest extends DicServiceBenchmarkTest {
          protected $maxAllowedTime = 100; // ms
      }
      
  4. Integration with Laravel:

    • Manual Trigger: Call the benchmark logic programmatically in a custom command:
      use Dawen\Bundle\DicServiceBenchmarkBundle\Service\BenchmarkService;
      $benchmark = new BenchmarkService($container);
      $results = $benchmark->run();
      
    • Laravel Service Provider: Bind the BenchmarkService to the container for reuse.

Gotchas and Tips

Pitfalls

  1. False Positives:

    • Heavy services (e.g., database connections, HTTP clients) may legitimately exceed 50ms.
    • Fix: Ignore them via dic-service-benchmark-ignore or adjust the threshold.
  2. Environment Dependencies:

    • Instantiation times vary across environments (dev/staging/prod).
    • Tip: Run benchmarks in a staging-like environment for realistic results.
  3. Lazy Services:

    • Services with lazy initialization (e.g., App\Services\LazyService::class) may show inconsistent times.
    • Workaround: Force eager loading in tests or exclude them.
  4. No Laravel-Specific Docs:

    • The package targets Symfony’s DIC. Laravel users must:
      • Use Illuminate\Container\Container as the DIC.
      • Manually bind the BenchmarkService if not auto-discovered.
  5. Test Isolation:

    • The bundled test assumes a clean DIC. Avoid running it mid-request (e.g., in a controller).

Debugging Tips

  • Verbose Output: Check the test’s run() method for debug logs (not exposed in README).
  • Service-Specific Issues:
    • Slow services often indicate:
      • Missing @Lazy annotations (Symfony).
      • Heavy constructor logic (e.g., loading config files).
      • Circular dependencies.
    • Action: Profile individual services with microtime(true) or Xdebug.

Extension Points

  1. Custom Benchmark Logic:

    • Extend Dawen\Bundle\DicServiceBenchmarkBundle\Service\BenchmarkService to:
      • Add pre/post-hooks for each service.
      • Log results to a database or file.
    • Example:
      class ExtendedBenchmarkService extends BenchmarkService {
          public function run() {
              $results = parent::run();
              $this->logResults($results); // Custom logic
              return $results;
          }
      }
      
  2. Visualization:

    • Parse output into a dashboard (e.g., Grafana) for trend analysis.
    • Example CLI output format:
      Service: app.service.foo | Time: 12.34ms | Status: OK
      Service: app.service.bar | Time: 67.89ms | Status: FAIL (threshold: 50ms)
      
  3. Parallel Testing:

    • Use PHPUnit’s --parallel flag to speed up benchmarking across multiple services.
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony