[Serializer][Validator] Skip mapping files for the classes they do not map
The loader chain calls every loader for every class, and each file loader parses its own file on the first call. An application that maps with files therefore parses all of them on the first class of a request, whatever that class is: one object costs the same as three hundred. The classes a mapping file maps are known at build time, since both components already expose getMappedClasses(). The bundles now read them while they collect the files, and hand the chain the set of classes of each loader, which skips a file loader for the classes it does not map. The classes are the keys of that set, so the chain has nothing to prepare when it is created. Loaders that declare nothing, such as the attribute loader, keep being called for every class. Nothing is cached, so this is safe whatever else the chain reads from: the result depends only on the mapping files, which the container now tracks. On an application with 83 validation and 83 serialization mapping files, the first validate() of a request goes from 330 ms to 31 ms, and the first serialize() from 113 ms to 3 ms. The container build parses each file once, which is not measurable next to the rest of the build.
N
Nicolas Grekas committed
28d1bbf338b04316132b3ed426ed8cee23825ff0
Parent: 5945ec3