Skip to content

[Serializer] Performance degradation #54865

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

Closed
mateuszsip opened this issue May 8, 2024 · 3 comments
Closed

[Serializer] Performance degradation #54865

mateuszsip opened this issue May 8, 2024 · 3 comments

Comments

@mateuszsip
Copy link
Contributor

mateuszsip commented May 8, 2024

Symfony version(s) affected

7.0.7, 6.4.7

Description

Recently after renovate upgrade bumping a few SF components (including serializer bump 6.4.6 -> 6.4.7) we noticed that our service started having performance problems on one endpoint.

CPU usage went to 100%, service autoscaled up to the limit and we've noticed on traces that service is getting stuck on processing not related to any IO operations.

What's specific about this endpoint is that we receive large json strings that are at some point getting serialized/deserialized and that's what got slow after upgrade.

At some point I even upgraded service to SF 7.0.7 and problem didn't go away.
It looks that downgrading to 6.4.6 or 7.0.6 helps, so I believe that root cause is here: symfony/serializer@v7.0.6...v7.0.7

I don't have any profiles that would tell exactly where it uses so much CPU the problem.

How to reproduce

I will do my best to prepare example repo later today.

Possible Solution

No response

Additional Context

We denormalize payload to an object that uses attributes with serialization group and public getters/setters.
See that changes between tags are related to that.

To test fixes, I prepared a load test using example payload (~850kb)
image
And p95 went to above 15s on 7.0.7.

Where on revision with a simple serializer dowgrade to 7.0.6 and exactly the same test it's back to normal:
image

@stloyd
Copy link
Contributor

stloyd commented May 8, 2024

I can confirm that this issue occurs on 7.0.7 but not on the previous one:
Zrzut ekranu 2024-05-6 o 16 27 17
Zrzut ekranu 2024-05-6 o 16 27 33

Most likely created after the merge of #52917, as you can see above, especially affected seems to be that method: https://github.com/symfony/symfony/pull/52917/files#diff-397b4689ce56cc95e54911f6d78639bb3258a9ee9b36bfa06ec719e9635e6b1dR195

@greg0ire
Copy link
Contributor

Cc @mtarld

@mtarld
Copy link
Contributor

mtarld commented May 17, 2024

Just created a PR caching the check whether a property is readable or writable. Could you try on your project @mateuszsip and @stloyd?
Thanks for the great detailed issue btw 🙂

@fabpot fabpot closed this as completed May 21, 2024
fabpot added a commit that referenced this issue May 21, 2024
…arld)

This PR was merged into the 6.4 branch.

Discussion
----------

[Serializer] Cache readability/writability computation

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54865
| License       | MIT

Add in memory cache to reduce the number of times we check whether a property is readable or writable.

Commits
-------

94fd291 [Serializer] Cache readability/writability computation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants