JMSSerializer and Hateoas performances

890 views
Skip to first unread message

dalex...@jolicode.com

unread,
Aug 8, 2014, 10:01:41 AM8/8/14
to resting-wi...@googlegroups.com
Hi everyone.

I'm currently performing some profiling on an API I work on,
and I'm kind of surprise by the cost of serialization.

I serialize a collection of 12 objects with ~25 properties (that's a small one),
and use Hateoas to add some links. 

The serialization part only take about 40ms on my machine, for such a small collection. that's 70% of my total request time.

Here is some of the most expensive calls:

- JMS\Serializer\GraphNavigator::accept
- JMS\Serializer\GenericSerializationVisitor::visitProperty
- JMS\Serializer\Metadata\PropertyMetadata::getValue
- Hateoas\Serializer\EventSubscriber\JsonEventSubscriber::onPostSerialize

I'm going through the code to find some bottlenecks but it's mostly that `accept` method in the GraphNavigator, called 300+ times.

So my question is about your feedback,
do you also experience slow responses times when using the full stack Serializer/Hateoas suite? 
what can we do to improve the speed?
what response time should I expect? 

Thx everyone,
Damien

Lukas Kahwe Smith

unread,
Aug 8, 2014, 10:05:09 AM8/8/14
to dalex...@jolicode.com, resting-wi...@googlegroups.com
We have noticed this as well.
I suspect that quite a bit could be gained from ordering the visitors properly and ensuring that they stop the visitor chain as early as possible.

However for now we just "threw HHVM at the problem"
http://blog.liip.ch/archive/2013/10/29/hhvm-and-symfony2.html

regards,
Lukas Kahwe Smith
sm...@pooteeweet.org



signature.asc

Stepan Anchugov

unread,
Aug 18, 2014, 2:44:03 AM8/18/14
to resting-wi...@googlegroups.com
I'm afraid Serializer's overhead will be pretty big no matter what you do. You'll only be able to reduce it a bit, I wouldn't expect any big improvements there. Did you look into hydrating your objects as an array, not as entities? This could produce better results IMO. 

dalex...@jolicode.com

unread,
Aug 18, 2014, 4:17:06 AM8/18/14
to resting-wi...@googlegroups.com
Yeah,
I tried implementing custom handlers for my objects but they bypass completely the event system,
which is why the Serializer is useful (appending extra data, etc).

If I hydrate array, it's the same issue: JMSSerializer become an expensive json_encode without benefits.

I'm considering removing JMSSerializer as I'm not really using it (I only do JSON serialization, no XML nor de-serialization), thx for your answers.

Lukas Smith

unread,
Aug 18, 2014, 4:28:07 AM8/18/14
to dalex...@jolicode.com, resting-wi...@googlegroups.com

> On 18 Aug 2014, at 10:17, dalex...@jolicode.com wrote:
>
> Yeah,
> I tried implementing custom handlers for my objects but they bypass completely the event system,
> which is why the Serializer is useful (appending extra data, etc).
>
> If I hydrate array, it's the same issue: JMSSerializer become an expensive json_encode without benefits.
>
> I'm considering removing JMSSerializer as I'm not really using it (I only do JSON serialization, no XML nor de-serialization), thx for your answers.

Well if you are not leveraging JMSSerializer you can of course switch to just doing json_encode(). Note if you are using FOSRestBundle you can hook in a custom serializer that does just that. Also note if the needs a slightly more complex you can try out the core Serializer component.

regards,
Lukas
Reply all
Reply to author
Forward
0 new messages