The Performance Cost
During development, the reflection overhead is typically negligible. However, in production with many data objects, this analysis happens on every request unless cached.The good news: Laravel Data can operate without reflection by using cached analysis results.
Caching Structures
Cache all data object analysis before deploying to production:- Searches for all data objects in your application
- Analyzes each data object
- Stores the results in your configured cache
Configuration
Configure caching inconfig/data.php:
Cache Store
Specify which cache driver to use:Discovery Directories
Configure which directories to search:app/Data directory is searched recursively.
Discovery Method
The package uses php-structure-discoverer to find data classes.Reflection Discovery (Default)
Enabled by default:PHP Parser Discovery
Disable reflection and use the PHP parser instead:Why include vendor directory?
Why include vendor directory?
The parser can’t depend on reflection, so it needs to analyze the Laravel Data source code to understand what constitutes a data object.
Disabling Caching
Disable structure caching entirely:Testing
The cache is automatically disabled during tests to ensure analysis results are always up-to-date and cache mocks aren’t affected.
Deployment Workflow
Recommended workflow for production deployments:Viewing Cached Classes
See which classes were cached:Performance Impact
Without Caching
Reflection analysis on every request~5-10ms per data class (depending on complexity)
With Caching
Pre-analyzed structures from cache~0.1-0.5ms per data class
For applications with 50+ data objects, caching can reduce data-related overhead by 90%+.