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.5x faster than Other Serializer for complex mappings
  • Other mapper libraries are up to 4.9x 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: ~8.1μs per operation
- Plain PHP: ~0.34μs per operation
- Trade-off: ~24x slower, but with type safety, immutability and mapping
SimpleDto vs Plain PHP (without #[AutoCast]):
- SimpleDto: ~15.0μs per operation
- Plain PHP: ~0.34μs per operation
- Trade-off: ~44x slower, but with type safety, validation and immutability
SimpleDto vs Plain PHP (with #[AutoCast]):
- SimpleDto: ~15-16μs per operation (depending on casting needs)
- Plain PHP: ~0.3μs per operation
- Trade-off: ~44-46x 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: ~10-13μs per operation
- Plain PHP: ~0.1-0.2μs per operation
- Trade-off: ~77x slower, but with template syntax and automatic mapping
DataMapper vs Other Serializer:
- DataMapper: ~15-18μs per operation
- OtherSerializer: ~52-64μs per operation
- Benefit: 3.5x 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): ~15μs (44x slower than Plain PHP)
- SimpleDto (with AutoCast): ~15μs (44x slower than Plain PHP)
- AutoCast overhead: ~0%
Scenario 2: String types (casting needed)
- SimpleDto (with AutoCast): ~16μs (46x slower than Plain PHP)
- Casting overhead: ~3% (compared to correct types)

Key Insights:

  • #[AutoCast] adds ~0% overhead even when no casting is needed (due to reflection)
  • Actual casting adds only ~3% 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.044μsGet value from flat array
Nested Get0.367μsGet value from nested path
Wildcard Get0.680μsGet values using single wildcard
Deep Wildcard Get30.771μsGet values using multiple wildcards
Typed Get String0.065μsGet typed string value
Typed Get Int0.063μsGet typed int value
Create Accessor0.046μsInstantiate DataAccessor
OperationTimeDescription
Simple Set0.876μsSet value in flat array
Nested Set1.100μsSet value in nested path
Deep Set1.201μsSet value creating new nested structure
Multiple Set1.518μsSet multiple values at once
Merge1.081μsDeep merge arrays
Unset1.074μsRemove single value
Multiple Unset1.407μsRemove multiple values
Wildcard Set1.525μs
Deep Wildcard Set3.987μs
OperationTimeDescription
Simple Mapping10.024μsMap flat structure
Nested Mapping10.376μsMap nested structure
Auto Map8.073μsAutomatic field mapping
Map From Template11.113μ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 Normal5.653μs31.815μs5.662μs
SimpleDto #[UltraFast]4.674μs
(1.2x faster)
30.065μs4.643μs
(1.2x faster)
LiteDto3.669μs
(1.5x faster)
6.542μs
(4.9x faster)
3.683μs
(1.5x faster)
LiteDto #[UltraFast]2.323μs
(2.4x faster)
4.354μs
(7.3x faster)
2.343μs
(2.4x faster)
Plain PHP0.079μs
(71.3x faster)
--
Other Dtos2.674μs
(2.1x faster)
3.283μs
(9.7x faster)
2.655μs
(2.1x faster)

Key Insights:

  • #[UltraFast] mode provides 1.8x faster performance than normal SimpleDto
  • #[UltraFast] is only ~111x slower than Plain PHP (vs ~197x 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
DataMapper10.118μs12.256μs12.356μs
SimpleDto #[UltraFast]4.674μs
(2.2x faster)
8.733μs
(1.4x faster)
-
Plain PHP0.048μs
(212.3x faster)
0.103μs
(118.6x faster)
-
Other Mappers2.060μs
(4.9x faster)
N/AN/A

Key Insights:

  • SimpleDto #[UltraFast] is 2.2x faster than DataMapper for simple mapping
  • Other mapper libraries are up to 4.9x faster than DataMapper, and 2.3x faster than #[UltraFast]
  • Plain PHP is ~212x 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
DataMapper19.707μs13.384μs
SimpleDto #[UltraFast]4.674μs
(4.2x faster)
4.674μs
(2.9x faster)
Plain PHP0.255μs
(77.2x faster)
0.255μs
(52.4x faster)
Other Serializer58.289μs
(3.0x slower)
58.289μs
(4.4x slower)

Key Insights:

  • SimpleDto #[UltraFast] is 12.5x faster than Other Serializer!
  • SimpleDto #[UltraFast] is 3.5x faster than DataMapper for simple mappings
  • DataMapper is 3.5x 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.71 μs
- MTIME (auto-validation): 2.71 μs
- HASH (auto-validation): 2.72 μs

Skip unnecessary operations for maximum DTO instantiation speed:

Normal Dto: 1.62 μs (baseline)
#[UltraFast]: 1.24 μs (23.3% faster)
#[NoCasts]: 1.10 μs (32.3% faster)
#[NoValidation]: 1.57 μs (3.1% faster)
#[NoAttributes]: 1.57 μs (3.1% faster)
#[NoCasts, NoValidation]: 1.07 μs (34.0% faster)
#[NoAttributes, NoCasts]: 1.58 μs (2.2% faster)
AutoCast Dto: 1.65 μs (with type casting)
#[NoCasts]: 1.07 μs (35.6% faster)
SimpleDto: 1.62 ms
#[UltraFast]: 1.24 ms (23.3% faster)
#[NoCasts]: 1.10 ms (32.3% faster)
#[NoAttributes, NoCasts]: 1.58 ms (2.2% faster)
Savings per 1M requests: ~376ms (0.4s) with #[UltraFast]