Symfony News

New in Symfony 4.1: Faster serializer

Kévin Dunglas Nicolas Grekas

Contributed by Kévin Dunglas and Nicolas Grekas in #27049 and #27105.

The Serializer component will be much faster in Symfony 4.1, improving the performance of your applications up to 40%. Best of all, you don't have to make any change in your code to make it faster. Just upgrade to Symfony 4.1 when it releases at the end of this month.

If you have used the Symfony serializer, you probably know that it works by normalizing/denormalizing PHP objects into arrays and then encoding/decoding that array into the desired format (JSON, XML, etc.)

Applications can define lots of normalizers/denormalizers and Symfony must call to the supportsNormalization() method of each of them whenever a new object is normalized/denormalized. In theory the result of supportsNormalization() can depend on multiple factors. In practice most normalizers only depend on the type and format and that information is easily cacheable.

That's the trick used to improve the Serializer performance. We've introduced a new CacheableSupportsMethodInterface for those normalizers/denormalizers that only use the type and the format in their supports*() methods:

1
2
3
4
5
6
namespace Symfony\Component\Serializer\Normalizer;

interface CacheableSupportsMethodInterface
{
    public function hasCacheableSupportsMethod(): bool;
}

We've already implemented this interface in all the built-in normalizers, so you don't have to change your code. If you have created your own normalizers, check if they can be cached in the same way and implement the interface if needed.

According to our own benchmarks, this change can make simple apps which use few normalizers up to 10% faster. Complex applications with lots of normalizers, such as Api Platform apps, can be up to 40% faster.


Be trained by Symfony experts - 2018-05-22 Clichy - 2018-05-22 Paris - 2018-05-22 Clichy


About us

What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...

Resources

Find us on Twitter

Find us on Facebook