The Dynamic Resource Optimization system is the core feature that makes CPSIT Quality Tools "just work" on projects of any size without manual configuration. This guide explains how the optimization works and how to customize it when needed.
Every command automatically analyzes your project and optimizes memory limits, processing strategies, and performance settings. This eliminates common issues like memory exhaustion on large projects and provides significant performance improvements.
Key Benefits:
- Zero Configuration Required: All optimization happens automatically
- 50%+ Performance Improvement: On large projects through smart optimization
- Memory Issue Resolution: Eliminates PHPStan and PHP CS Fixer memory exhaustion
- Smart Path Scoping: Focuses analysis on relevant code (defaults to
/packagesdirectory) - Consistent Experience: All tools use the same optimization strategy
Every command starts by analyzing your project:
$ vendor/bin/qt lint:phpstan
Project Analysis: Analyzing TYPO3 project structure...
Project Analysis: Found 1,001 files (174 PHP files) in /packages
Optimization: Setting PHPStan memory limit to 552M for medium project
Optimization: Enabling parallel processing for improved performanceThe system analyzes:
- File Count: Total files and files per type (PHP, YAML, JSON, XML)
- Project Size: Small (<100 files), Medium (100-1000), Large (1000-5000), Enterprise (>5000)
- Code Complexity: Lines of code, complexity metrics
- Project Type: TYPO3 vs generic PHP project detection
Memory limits are calculated dynamically based on project characteristics:
| Project Size | File Range | PHPStan Memory | PHP CS Fixer Memory | Rector Memory |
|---|---|---|---|---|
| Small | < 100 files | 256M | 256M | 384M |
| Medium | 100-1000 files | 552M | 460M | 690M |
| Large | 1000-5000 files | 1024M | 768M | 1200M |
| Enterprise | > 5000 files | 2048M | 1536M | 2048M |
Memory Calculation Algorithm:
- Base memory: 128MB
- PHP files: 0.5MB per file + complexity factor
- Other files: 0.1MB per file
- Tool-specific multipliers applied
- Reasonable limits: 256MB minimum, 2GB maximum
For larger projects, additional optimizations are automatically enabled:
Parallel Processing:
- Enabled automatically for projects with 500+ files
- Improves processing speed by 40-60%
- Uses optimal core count detection
Caching:
- Automatic cache enablement for supported tools
- Significantly speeds up repeated runs
- Cache files stored in system temp directory
Path Scoping:
- TYPO3 projects default to analyzing
/packagesdirectory only - Avoids analyzing vendor code (reduces from 48K+ to 1K files typically)
- Custom paths can be specified with
--pathoption
Project Analysis: Analyzing TYPO3 project structure...
Project Analysis: Found 45 files (12 PHP files) in /packages
Optimization: Setting PHPStan memory limit to 256M for small project
Optimization: Standard processing mode selected
Performance: Analysis completed in 8.2 seconds
Project Analysis: Analyzing TYPO3 project structure...
Project Analysis: Found 1,001 files (174 PHP files) in /packages
Optimization: Setting PHPStan memory limit to 552M for medium project
Optimization: Enabling parallel processing for improved performance
Performance: Analysis completed in 45.3 seconds (estimated 89s without optimization)
Project Analysis: Analyzing TYPO3 project structure...
Project Analysis: Found 2,847 files (423 PHP files) in /packages
Optimization: Setting Rector memory limit to 1200M for large project
Optimization: Enabling parallel processing and caching for performance
Optimization: Using chunked processing for memory efficiency
Performance: Processing completed in 3m 12s (estimated 6m 45s without optimization)
While optimization works automatically, advanced users can override settings:
# Disable all automatic optimization
vendor/bin/qt lint:phpstan --no-optimization
# Use tool defaults instead of calculated values
vendor/bin/qt fix:rector --no-optimizationOptimization details are shown by default for all commands:
# Optimization details are shown automatically
vendor/bin/qt lint:phpstan
# Example output:
# Project Analysis: Project size: MEDIUM (1,001 files)
# Project Analysis: PHP files: 174, Complexity score: 3.2
# Memory Calculation: Base 128M + PHP factor 87M + complexity 32M = 247M
# Memory Calculation: Applied PHPStan multiplier 2.24x = 552M
# Performance: Parallel processing enabled (8 cores detected)
# Performance: Caching enabled for repeated runs# Override automatic memory calculation
vendor/bin/qt lint:phpstan --memory-limit=1024M
# Override with custom level
vendor/bin/qt lint:phpstan --level=8 --memory-limit=1536M# Analyze specific path instead of automatic /packages detection
vendor/bin/qt lint:phpstan --path=./custom/extension
# Analyze entire project (not recommended for large projects)
vendor/bin/qt lint:phpstan --path=.All commands show performance information:
Performance: Analysis completed in 45.3 seconds
Performance: Memory peak usage: 387M / 552M allocated
Performance: Files processed: 1,001 (174 PHP files analyzed)
Performance: Optimization saved estimated 43.7 seconds
Memory Usage: Peak 387M / 552M allocated (70% utilization)
Memory Usage: Optimization prevented memory exhaustion
Memory Usage: Without optimization: estimated 650M+ required
Project Analysis: File type breakdown:
- PHP files: 174 (primary analysis target)
- TypoScript files: 67 (configuration files)
- YAML files: 89 (configuration files)
- JSON files: 23 (composer, package files)
- Other files: 648 (templates, assets, etc.)
Control optimization behavior globally:
# Disable optimization for all commands
export QT_NO_OPTIMIZATION=1
# Set global memory multiplier
export QT_MEMORY_MULTIPLIER=1.5
# Set minimum memory limit
export QT_MIN_MEMORY=512MFor project-wide settings, create .qt-config.yaml:
optimization:
enabled: true
memory:
phpstan_multiplier: 2.5
php_cs_fixer_multiplier: 1.8
rector_multiplier: 3.0
performance:
parallel_threshold: 300
cache_enabled: true
paths:
typo3_default: "packages"
analysis_depth: 10Memory Still Insufficient:
# If automatic calculation is too low, override manually
vendor/bin/qt lint:phpstan --memory-limit=2048M
# Or disable optimization and use tool defaults
vendor/bin/qt lint:phpstan --no-optimizationPerformance Slower Than Expected:
# Optimization details are shown by default, check the output
vendor/bin/qt lint:phpstan
# Verify path scoping is working
# Should show "Found X files in /packages" not entire projectOptimization Not Working:
# Check project detection (details shown by default)
vendor/bin/qt lint:phpstan
# Verify TYPO3 project detection:
# Should show "TYPO3 project detected" in analysis output# Enable debug output for detailed optimization information
vendor/bin/qt lint:phpstan --debug
# Shows:
# - Project detection logic
# - File counting process
# - Memory calculation steps
# - Performance optimization decisions- Project Root Detection: Traverse up to find TYPO3 composer.json
- File System Analysis: Count files by type using RecursiveDirectoryIterator
- Complexity Analysis: Calculate code metrics for PHP files
- Size Classification: Categorize project as Small/Medium/Large/Enterprise
- Optimization Selection: Apply appropriate optimization profile
memory = base_memory + (php_files * 0.5MB) + (complexity_factor * 0.1MB) + (other_files * 0.1MB)
final_memory = min(max(memory * tool_multiplier, 256MB), 2048MB)
- PHPStan: 2.24x (AST analysis is memory intensive)
- PHP CS Fixer: 1.8x (token analysis requires significant memory)
- Rector: 3.0x (code transformation requires most memory)
- Fractor: 2.0x (TypoScript parsing and transformation)
Real-world performance improvements with optimization enabled:
| Project Size | Files | Without Optimization | With Optimization | Improvement |
|---|---|---|---|---|
| Small | 45 | 12.3s | 8.2s | 33% |
| Medium | 1,001 | 89.4s | 45.3s | 49% |
| Large | 2,847 | 6m 45s | 3m 12s | 53% |
| Enterprise | 8,234 | Memory Error | 8m 34s | Previously Impossible |
Planned optimization improvements:
- Machine Learning Optimization: Learn from project patterns to improve predictions
- CI/CD Integration: Optimize specifically for build environments
- Tool Chain Optimization: Optimize across multiple tool runs
- Memory Profiling: Real-time memory usage optimization
- Custom Optimization Profiles: Save and share optimization configurations
The Dynamic Resource Optimization system represents a major quality-of-life improvement, ensuring that quality tools "just work" regardless of project size while providing significant performance benefits.