PHP package compiles DTO hydration closures to hit 4.5M operations per second
A new PHP 8.4+ package called Simple Data Objects eliminates the performance overhead typically associated with attribute-driven Data Transfer Objects. Instead of running reflection and attribute reads on every call, the package performs all reflection once and compiles a specialized closure per data class. Plain properties are reduced to direct array reads, while cast properties delegate to a runtime handler, with all per-parameter branching resolved at compile time. The generated hydrators are persisted in an opcache-served cache, and PHP 8.4 lazy ghosts further defer hydration until a property is first accessed. The approach targets use cases such as hydrating thousands of database rows or serializing nested API object graphs, where repeated generic dispatch loops become a measurable bottleneck.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in