Skip to content

Performance Modes

SimpleDto provides multiple performance modes to balance features and speed based on your needs.

ModeSpeedFeaturesUse Case
Normal12.7μsFull featuresDefault mode with all features
#[UltraFast]1.7μsMinimalMaximum speed with basic mapping
#[NoCasts]~8μsNo castingSkip type casting
#[NoValidation]~10μsNo validationSkip validation
#[NoAttributes]~9μsNo attributesSkip attribute processing

The #[UltraFast] attribute provides maximum performance by bypassing all SimpleDto overhead.

  • 7.4x faster than normal SimpleDto
  • Direct reflection (no cache overhead)
  • Minimal memory (2.7mb vs 6.7mb)
  • ✅ Supports #[MapFrom] and #[MapTo] attributes
  • ✅ Handles nested DTOs recursively
  • ❌ No validation
  • ❌ No type casting
  • ❌ No lazy loading
  • ❌ No optional properties
  • ❌ No computed properties
use event4u\DataHelpers\SimpleDto;
use event4u\DataHelpers\SimpleDto\Attributes\UltraFast;
use event4u\DataHelpers\SimpleDto\Attributes\MapFrom;
#[UltraFast]
class FastUserDto extends SimpleDto
{
public function __construct(
#[MapFrom('user_name')]
public readonly string $name,
public readonly string $email,
public readonly int $age,
) {}
}
// Create from array (1.7μs)
$user = FastUserDto::fromArray([
'user_name' => 'John Doe',
'email' => 'john@example.com',
'age' => 30,
]);
// Convert to array
$array = $user->toArray();
// ['name' => 'John Doe', 'email' => 'john@example.com', 'age' => 30]
#[UltraFast]
class FastAddressDto extends SimpleDto
{
public function __construct(
public readonly string $street,
public readonly string $city,
) {}
}
#[UltraFast]
class FastUserDto extends SimpleDto
{
public function __construct(
public readonly string $name,
public readonly FastAddressDto $address,
) {}
}
$user = FastUserDto::fromArray([
'name' => 'John',
'address' => [
'street' => '123 Main St',
'city' => 'New York',
],
]);
#[UltraFast(
allowMapFrom: true, // Allow #[MapFrom] attributes (default: true)
allowMapTo: true, // Allow #[MapTo] attributes (default: true)
allowCastWith: false, // Allow #[CastWith] attributes (default: false)
)]
class ConfiguredDto extends SimpleDto
{
// ...
}

Skip all type casting for better performance when input data is already correctly typed.

  • 34-63% faster than normal SimpleDto
  • ✅ All other features work (validation, mapping, etc.)
  • ❌ No automatic type conversion
  • ❌ No nested DTO auto-casting
use event4u\DataHelpers\SimpleDto\Attributes\NoCasts;
#[NoCasts]
class StrictDto extends SimpleDto
{
public function __construct(
public readonly string $name,
public readonly int $age,
) {}
}
// This works (correct types)
$dto = StrictDto::fromArray(['name' => 'John', 'age' => 30]);
// This throws TypeError (wrong types, no casting)
$dto = StrictDto::fromArray(['name' => 'John', 'age' => '30']);

Skip validation for better performance when input data is already validated.

  • 20-30% faster than normal SimpleDto
  • ✅ All other features work (casting, mapping, etc.)
  • ❌ No validation attributes processed
use event4u\DataHelpers\SimpleDto\Attributes\NoValidation;
#[NoValidation]
class TrustedDto extends SimpleDto
{
public function __construct(
public readonly string $name,
public readonly string $email,
) {}
}

Skip all attribute processing for maximum performance.

  • 25-40% faster than normal SimpleDto
  • ✅ Basic DTO functionality works
  • ❌ No validation attributes
  • ❌ No visibility attributes
  • ❌ No mapping attributes
  • ❌ No cast attributes
use event4u\DataHelpers\SimpleDto\Attributes\NoAttributes;
#[NoAttributes]
class MinimalDto extends SimpleDto
{
public function __construct(
public readonly string $name,
public readonly int $age,
) {}
}

You can combine multiple performance attributes:

#[NoCasts, NoValidation]
class FastDto extends SimpleDto
{
public function __construct(
public readonly string $name,
public readonly int $age,
) {}
}
Benchmark Results (10,000 iterations):
Normal SimpleDto: 12.740μs (baseline)
#[NoValidation]: ~10.000μs (20% faster)
#[NoAttributes]: ~9.000μs (29% faster)
#[NoCasts]: ~8.000μs (37% faster)
#[NoCasts, NoValidation]: ~6.000μs (53% faster)
#[UltraFast]: 1.723μs (639% faster)
Plain PHP Constructor: 0.141μs (9,000% faster)
Other Dto Libraries: 0.315μs (4,000% faster)
  • ✅ You need full features (validation, casts, mapping)
  • ✅ Performance is acceptable (not in tight loops)
  • ✅ Developer experience is priority
  • ✅ Type safety and validation are important
  • ✅ You need maximum speed
  • ✅ You only need basic mapping (#[MapFrom], #[MapTo])
  • ✅ Input data is already validated
  • ✅ Input data is already correctly typed
  • ✅ You’re processing large datasets
  • ✅ Input data is already correctly typed
  • ✅ You need validation but not casting
  • ✅ You want better performance without losing features
  • ✅ Input data is already validated (e.g., from database)
  • ✅ You need casting but not validation
  • ✅ You trust the data source
  • ✅ You don’t use any attributes
  • ✅ You want simple DTOs with better performance
  • ✅ You only need basic fromArray/toArray functionality
// API endpoint - needs validation and casting
class CreateUserRequest extends SimpleDto
{
#[Required, Email]
public readonly string $email;
#[Required, Min(3)]
public readonly string $name;
}
// Internal DTO - already validated, use #[UltraFast]
#[UltraFast]
class UserDto extends SimpleDto
{
public function __construct(
public readonly string $email,
public readonly string $name,
public readonly int $id,
) {}
}
// Database result - already typed, use #[NoCasts]
#[NoCasts]
class UserFromDatabase extends SimpleDto
{
public function __construct(
public readonly int $id,
public readonly string $email,
public readonly string $name,
) {}
}