Performance & Caching
Data Helpers is optimized for performance with built-in caching and efficient algorithms.
Performance Benchmarks
Section titled “Performance Benchmarks”DataMapper is significantly faster than traditional serializers:
- 3.7x faster than Symfony Serializer for Dto mapping
- 2.3x faster lazy cast speedup
- 914,000 instances/sec Dto creation rate
See Performance Benchmarks for detailed comparisons.
Caching
Section titled “Caching”Path Caching
Section titled “Path Caching”Dot-path parsing is automatically cached:
// First call: Parse and cache$value1 = $accessor->get('user.profile.name');
// Subsequent calls: Use cached path$value2 = $accessor->get('user.profile.name'); // Faster!Template Caching
Section titled “Template Caching”DataMapper templates are compiled and cached:
$data = ['name' => 'John', 'email' => 'john@example.com'];$template = ['user_name' => '{{ name }}', 'user_email' => '{{ email }}'];
// First call: Compile and cache template$result1 = DataMapper::source($data)->template($template)->map();
// Subsequent calls: Use cached template$result2 = DataMapper::source($data)->template($template)->map(); // Faster!Optimization Tips
Section titled “Optimization Tips”Use Explicit Paths
Section titled “Use Explicit Paths”Explicit paths are faster than wildcards:
// Faster$name = $accessor->get('users.0.name');
// Slower (iterates all items)$names = $accessor->get('users.*.name');Apply Filters Early
Section titled “Apply Filters Early”Filter data before mapping:
$template = [ 'active_users' => [ 'WHERE' => ['{{ users.*.active }}' => true], // Filter first 'ORDER BY' => ['{{ users.*.name }}' => 'ASC'], '*' => ['name' => '{{ users.*.name }}'], ],];Use Lazy Properties
Section titled “Use Lazy Properties”Lazy properties are only computed when accessed:
class UserDto extends SimpleDto{ #[Lazy] public string $fullName;
protected function computeFullName(): string { return $this->firstName . ' ' . $this->lastName; }}Batch Operations
Section titled “Batch Operations”Process multiple items at once:
// Faster: Single wildcard operation$mutator->set('orders.*.status', 'shipped');
// Slower: Loop with individual operationsforeach ($data['orders'] as $i => $order) { $mutator->set("orders.{$i}.status", 'shipped');}Memory Usage
Section titled “Memory Usage”Data Helpers is memory-efficient:
- No Reflection Overhead - Template-based mapping avoids reflection
- Lazy Loading - Only load data when needed
- Efficient Caching - Minimal memory footprint