Benchmark MarkerAttribute #84

Closed
opened 2026-10-01 19:52:05 +02:00 by c.fahner · 1 comment
Owner

The method ::isMarked() for the MarkerAttribute trait is used quite frequently and inside loops (eg. Schema::fromClass()). The fastest way to check should be benchmarked and applied:

  • foreach ($reflector->getAttributes(static::class) as $_) { return true; }
  • return \count($reflector->getAttributes(static::class) > 0;
  • return isset($reflector->getAttributes(static::class)[0]);
  • return !empty($reflector->getAttributes(static::class)[0]);
  • ???
The method `::isMarked()` for the `MarkerAttribute` trait is used quite frequently and inside loops (eg. `Schema::fromClass()`). The fastest way to check should be benchmarked and applied: * `foreach ($reflector->getAttributes(static::class) as $_) { return true; }` * `return \count($reflector->getAttributes(static::class) > 0;` * `return isset($reflector->getAttributes(static::class)[0]);` * `return !empty($reflector->getAttributes(static::class)[0]);` * ???
c.fahner added this to the v0.2 milestone 2026-10-19 18:10:34 +02:00
Author
Owner

Only the foreach variant is marginally slower. The bottleneck seems to be the call to getAttributes().

Only the foreach variant is marginally slower. The bottleneck seems to be the call to `getAttributes()`.
c.fahner added spent time 2026-10-19 18:57:24 +02:00
30 minutes
c.fahner stopped working 2026-10-19 19:28:53 +02:00
31 minutes 25 seconds
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Total time spent: 1 hour 1 minute
c.fahner
1 hour 1 minute
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
slendium/ocd#84
No description provided.