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:
$mapper = new DataMapper();
// First call: Compile and cache template$result1 = $mapper->map($data, $template);
// Subsequent calls: Use cached template$result2 = $mapper->map($data, $template); // 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