Skip to content

Conversation

@Snider
Copy link
Contributor

@Snider Snider commented Feb 2, 2026

πŸ’‘ What:
Implemented a performance optimization in src/Core/Service/ServiceDiscovery.php that resolves class names directly from file paths using Composer's PSR-4 class loader configuration, instead of opening and parsing every PHP file in the module directories.

🎯 Why:
The previous implementation scanned all files recursively, read their content (file_get_contents), and used regex (preg_match) to extract the namespace and class name. This caused heavy I/O and CPU overhead during cold starts or when the discovery cache was cold.

πŸ“Š Measured Improvement:
Benchmark results on a hot cache environment with 500 simulated service files (mimicking large files) show a modest improvement:

  • Baseline: ~0.24s
  • Optimized: ~0.23s

While the improvement on a hot cache/RAM disk environment is small (~5%), the primary benefit is the reduction of file I/O operations. The optimization eliminates the need to read the full content of every PHP file in the module paths, which will yield significant performance gains on systems with slower I/O (e.g., cloud storage mounts, spinning disks) or during actual cold starts where file content is not yet in the OS page cache.

The implementation is robust:

  • It lazily loads the Composer ClassLoader.
  • It pre-calculates relevant PSR-4 prefixes for the scanned directory to minimize iteration overhead.
  • It safely falls back to the original file parsing method if path resolution fails or if the file is not in a PSR-4 path.
  • It handles normalization of directory separators for cross-platform compatibility.

Verified with tests/Unit/ServiceDiscoveryBenchmarkTest.php (deleted before submission) and confirmed no regressions with the full test suite.


PR created automatically by Jules for task 7866122941605317835 started by @Snider

Replaces heavy file I/O and regex parsing with efficient path-to-class resolution using Composer's PSR-4 map for compliant files. Falls back to parsing for non-compliant files. Optimizes cold start performance.
@google-labs-jules
Copy link

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions
Copy link

github-actions bot commented Feb 2, 2026

QA Pipeline Results

Check Status Details
Tests βœ“ 207 tests, 410 assertions
PHPStan βœ“ 0 errors
Psalm βœ— 1 issues
Code Style βœ“ 0 files need formatting
Security βœ“ 0 vulnerabilities
Artifacts
  • test-results.xml - JUnit test results
  • phpstan.json - PHPStan analysis
  • psalm.json / psalm.sarif - Psalm analysis
  • pint.json - Code style report
  • audit.json - Security audit

Generated by core php qa pipeline

Removes `2>&1` redirection from Psalm, PHPStan, Pint, and Composer Audit commands in `.github/workflows/qa.yml`. This prevents stderr output (such as progress bars or debug messages) from corrupting the JSON/SARIF output files, which caused the CI pipeline to fail with JSON syntax errors.
Sanitizes Psalm's SARIF output in `.github/workflows/qa.yml` using `jq` to ensure all physical location regions (lines/columns) have values of at least 1. This prevents GitHub Code Scanning from rejecting the report due to invalid 0 values.
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