Magento InterfaceValidator improvements
Important performance improvement in the Magento plugin system.
In Magento 2, the InterfaceValidator
is a component which role is to technically validate the plugins loaded in the system, by e.g. validating the plugins methods parameters and their type, or their origin method name (which corresponds to the loading order of each plugin). This class is an important axis of Magento plugin system and is called every single time a plugin is mentioned. It is therefore critical for it to be as optimized as possible.
In this context, Łukasz Bajsarowicz, who contributes to the Magento ecosystem on a regular basis, started to profile the InterfaceValidator
with the help of Blackfire. He implemented a few tweaks e.g.:
- Changing the order of conditions;
- Replacing the Elvis operator (
?:
) by the null coalescing operator (??
); - Replacing
substr
comparisons withstrpos
.
This may seem minimal, but it improved the overall performance of the component by 21%! Łukasz opened a pull-request on Magento
Thanks Łukasz for making Magento faster!