Skip to content

Serializer listener performance - anonymous class not serializable #1780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2018
Merged

Serializer listener performance - anonymous class not serializable #1780

merged 1 commit into from
Mar 19, 2018

Conversation

bendavies
Copy link
Contributor

@bendavies bendavies commented Mar 16, 2018

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1307
License MIT
Doc PR

In #1307, an anonymous class was introduced to fix a performance problem but it introduced another.

In these ItemNormalizers:
https://github.com/api-platform/core/blob/master/src/Hal/Serializer/ItemNormalizer.php#L219
https://github.com/api-platform/core/blob/master/src/JsonApi/Serializer/ItemNormalizer.php#L337

the context is serialized to produce a cache key, but anonymous classes are not serializable: https://3v4l.org/tvMGa.
This effectively disables the intended caching in the HAL and Json API item normalizers.

Blackfire comparison for a HAL endpoint returning 500 items
https://blackfire.io/profiles/compare/8994c0b0-8a09-4ae7-9c38-dd8ad72ecc22/graph

11% improvement.

@sroze
Copy link
Contributor

sroze commented Mar 16, 2018

Very good catch 👏

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow good catch men, nice!

@soyuka
Copy link
Member

soyuka commented Mar 19, 2018

@dunglas is it fine to merge this on 2.2? It can be considered as a bug fix imo not sure though.

@meyerbaptiste
Copy link
Member

This is clearly a bug because of the E_WARNING.

@meyerbaptiste meyerbaptiste merged commit b9d2b17 into api-platform:2.2 Mar 19, 2018
@meyerbaptiste
Copy link
Member

meyerbaptiste commented Mar 19, 2018

Thx @bendavies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants