Skip to content

Performance Benchmarks

Detailed performance benchmarks for Data Helpers.

Data Helpers provides powerful features with acceptable performance overhead:

  • Type safety and validation - With reasonable performance cost
  • 3.6x faster than Other Serializer for complex mappings
  • Other mapper libraries are up to 4.8x faster, but DataMapper provides better features
  • Low memory footprint - ~1.2 KB per instance

Data Helpers prioritizes developer experience, type safety and maintainability over raw speed:

SimpleDto #[UltraFast] vs Plain PHP:
- SimpleDto: ~9.9μs per operation
- Plain PHP: ~0.37μs per operation
- Trade-off: ~27x slower, but with type safety, immutability and mapping
SimpleDto vs Plain PHP (without #[AutoCast]):
- SimpleDto: ~17.1μs per operation
- Plain PHP: ~0.37μs per operation
- Trade-off: ~46x slower, but with type safety, validation and immutability
SimpleDto vs Plain PHP (with #[AutoCast]):
- SimpleDto: ~17μs per operation (depending on casting needs)
- Plain PHP: ~0.4μs per operation
- Trade-off: ~47x slower, but with automatic type conversion
- Note: Only use #[AutoCast] when you need automatic type conversion
(e.g., CSV, XML, HTTP requests with string values)
DataMapper vs Plain PHP:
- DataMapper: ~13-15μs per operation
- Plain PHP: ~0.1-0.3μs per operation
- Trade-off: ~69x slower, but with template syntax and automatic mapping
DataMapper vs Other Serializer:
- DataMapper: ~17-21μs per operation
- OtherSerializer: ~62-76μs per operation
- Benefit: 3.6x faster with better developer experience

The #[AutoCast] attribute provides automatic type conversion but comes with a performance cost:

Scenario 1: Correct types (no casting needed)
- SimpleDto (no AutoCast): ~17μs (46x slower than Plain PHP)
- SimpleDto (with AutoCast): ~17μs (47x slower than Plain PHP)
- AutoCast overhead: ~0%
Scenario 2: String types (casting needed)
- SimpleDto (with AutoCast): ~17μs (47x slower than Plain PHP)
- Casting overhead: ~1% (compared to correct types)

Key Insights:

  • #[AutoCast] adds ~0% overhead even when no casting is needed (due to reflection)
  • Actual casting adds only ~1% overhead on top of the AutoCast overhead
  • Without #[AutoCast], SimpleDto is ~1.0x faster and closer to Plain PHP performance

When to use #[AutoCast]:

  • ✅ CSV imports (all values are strings)
  • ✅ XML parsing (all values are strings)
  • ✅ HTTP requests (query params and form data are strings)
  • ✅ Legacy APIs with inconsistent types
  • ❌ Internal Dtos with correct types
  • ❌ Performance-critical code paths
  • ❌ High-throughput data processing

Use Data Helpers when:

  • You need type safety and validation
  • You work with complex data structures
  • You want maintainable, readable code
  • Performance is acceptable (not in tight loops)
  • You’re replacing Symfony Serializer or other heavy libraries

Consider Plain PHP or LiteDto when:

  • You’re in performance-critical tight loops
  • You process millions of operations per second
  • You don’t need validation or type safety
  • You’re willing to write and maintain manual mapping code
OperationTimeDescription
Simple Get0.061μsGet value from flat array
Nested Get0.490μsGet value from nested path
Wildcard Get0.917μsGet values using single wildcard
Deep Wildcard Get38.993μsGet values using multiple wildcards
Typed Get String0.086μsGet typed string value
Typed Get Int0.083μsGet typed int value
Create Accessor0.060μsInstantiate DataAccessor
OperationTimeDescription
Simple Set1.162μsSet value in flat array
Nested Set1.444μsSet value in nested path
Deep Set1.579μsSet value creating new nested structure
Multiple Set2.048μsSet multiple values at once
Merge1.467μsDeep merge arrays
Unset1.395μsRemove single value
Multiple Unset1.850μsRemove multiple values
Wildcard Set1.976μs
Deep Wildcard Set5.321μs
OperationTimeDescription
Simple Mapping12.234μsMap flat structure
Nested Mapping12.735μsMap nested structure
Auto Map10.091μsAutomatic field mapping
Map From Template13.389μsMap using template expressions
Dto Instance: ~1.2 KB
With Validation: ~1.5 KB
With Caching: ~0.8 KB

Comparison of our SimpleDto implementation with other Dto libraries and plain PHP:

ImplementationFrom ArrayTo ArrayComplex Data
SimpleDto Normal6.299μs38.534μs6.321μs
SimpleDto #[UltraFast]5.708μs
(1.1x faster)
37.787μs5.742μs
(1.1x faster)
LiteDto3.247μs
(1.9x faster)
6.447μs
(6.0x faster)
3.226μs
(2.0x faster)
LiteDto #[UltraFast]2.642μs
(2.4x faster)
4.728μs
(8.1x faster)
2.598μs
(2.4x faster)
Plain PHP0.111μs
(56.5x faster)
--
Other Dtos3.305μs
(1.9x faster)
4.002μs
(9.6x faster)
3.328μs
(1.9x faster)

Key Insights:

  • #[UltraFast] mode provides 1.7x faster performance than normal SimpleDto
  • #[UltraFast] is only ~96x slower than Plain PHP (vs ~166x for normal mode)
  • #[UltraFast] is competitive with other Dto libraries (~3x slower)
  • SimpleDto provides type safety, validation and immutability with reasonable overhead
  • The overhead is acceptable for the added safety and developer experience

Comparison of our DataMapper with other mapper libraries and plain PHP:

ImplementationSimple MappingNested MappingTemplate Mapping
DataMapper12.279μs14.700μs15.123μs
SimpleDto #[UltraFast]5.708μs
(2.2x faster)
10.751μs
(1.4x faster)
-
Plain PHP0.067μs
(184.1x faster)
0.136μs
(107.7x faster)
-
Other Mappers2.566μs
(4.8x faster)
N/AN/A

Key Insights:

  • SimpleDto #[UltraFast] is 2.2x faster than DataMapper for simple mapping
  • Other mapper libraries are up to 4.8x faster than DataMapper, and 2.2x faster than #[UltraFast]
  • Plain PHP is ~184x faster but requires manual mapping code for each use case
  • DataMapper provides the best balance of features, readability and maintainability for complex mappings

Comparison with external serializers for nested JSON to Dto mapping:

ImplementationTemplate SyntaxSimple Paths
DataMapper22.625μs15.933μs
SimpleDto #[UltraFast]5.708μs
(4.0x faster)
5.708μs
(2.8x faster)
Plain PHP0.322μs
(70.3x faster)
0.322μs
(49.5x faster)
Other Serializer69.100μs
(3.1x slower)
69.100μs
(4.3x slower)

Key Insights:

  • SimpleDto #[UltraFast] is 12.1x faster than Other Serializer!
  • SimpleDto #[UltraFast] is 3.4x faster than DataMapper for simple mappings
  • DataMapper is 3.6x faster than Other Serializer for complex mappings
  • Zero reflection overhead for template-based mapping
  • Optimized for nested data structures

Data Helpers supports different cache invalidation strategies with varying performance characteristics:

Cache Invalidation Modes (50,000 iterations, warm cache):
- MANUAL (no validation): 2.62 μs
- MTIME (auto-validation): 2.68 μs
- HASH (auto-validation): 2.84 μs

Skip unnecessary operations for maximum DTO instantiation speed:

Normal Dto: 1.72 μs (baseline)
#[UltraFast]: 1.56 μs (9.1% faster)
#[NoCasts]: 1.05 μs (39.0% faster)
#[NoValidation]: 1.83 μs (6.5% slower)
#[NoAttributes]: 1.75 μs (1.6% slower)
#[NoCasts, NoValidation]: 1.10 μs (36.2% faster)
#[NoAttributes, NoCasts]: 1.72 μs (0.2% faster)
AutoCast Dto: 1.79 μs (with type casting)
#[NoCasts]: 1.02 μs (43.0% faster)
SimpleDto: 1.72 ms
#[UltraFast]: 1.56 ms (9.1% faster)
#[NoCasts]: 1.05 ms (39.0% faster)
#[NoAttributes, NoCasts]: 1.72 ms (0.2% faster)
Savings per 1M requests: ~157ms (0.2s) with #[UltraFast]