Problem/Motivation
During performance testing in JSON:API module it showed that a HUGE portion of the time was spent fetching normalizers. You can check the whole story here:
- #3014283: Use ResourceTypeFields to statically determine the field normalizer
- #3016129: [upstream] Fetching normalizers seems slow
Upstream issue in symfony/serializer: https://github.com/symfony/symfony/issues/29387. The problem in the end is that the issue is present only in symfony/serializer version 3.4.x and it's already resolved somewhere in 4.x.
As core is bound to 3.4.x how complex would it be to move to symfony/serializer that has this HUGE performance improvement.
Marking it as critical because of this 2 reasons (details):
- Over ~100ms or more savings with cold caches. In my use case the savings are way over that.
- Gets measurably worse with lots of contrib modules or large data sets... - the issue IS data bound and the only way to limit the effects of it, is to introduce the particular cache layer that is laready present in 4.x.
Proposed resolution
I see some options that all should be discussed and decided on:
- Upgrade to latest possible serializer package - best, maybe hard...
- Have the package upgraded and implement a backwards compatible adapter for it, so existing code can be fixed easily.
- Have a patch (and maintain it) and ship core with a patched dependency.
- Any other ideas? ...
This is affecting everything that uses the serializer systems mainly REST, GraphQL and JSON:API.
Remaining tasks
Discussion, decision, Plan, Patch, etc...
User interface changes
TBD.
API changes
TBD.
Data model changes
TBD.
Release notes snippet
TBD.
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 3017291-23.patch | 1.18 KB | br0ken |
| #10 | 3017291-10-2.patch | 3.68 KB | ndobromirov |
| #8 | drupal-symfony-serializer-34-41-3017291.patch | 17.13 KB | ndobromirov |
Comments
Comment #2
ndobromirov commentedComment #3
ndobromirov commentedComment #4
ndobromirov commentedComment #5
wim leersCritical means things are on fire. Things aren't on fire, they merely running hot, and have been for years :)
Comment #6
wim leersAlso: thank you very much for creating this issue! 👍 🎉
Comment #7
ndobromirov commentedLet's have the ball rolling...
How much will that break updating to D8 serializer dependency to 4.1 :) ?
Comment #8
ndobromirov commentedHere is an initial patch. First observations is the PHP 7.1+.
Comment #10
ndobromirov commentedStrange. Rebased the patch...
Comment #11
ndobromirov commentedComment #13
ndobromirov commentedSo the only blocker in the test suite is against PHP version limits, as 8.7 will try to support
PHP 5, as discussed in #2842431: [policy] Remove PHP 5.5, 5.6 support in Drupal 8.7.As I see it, this is an
8.8.xmaterial, as at that point PHP 5 will no longer be supported and hopefully we will be able to up this one.Comment #14
ndobromirov commentedIs there a way to have this sooner?
Comment #15
wim leersYou'd have to land a change in Symfony 3.x, in https://github.com/symfony/symfony.
Comment #16
wim leersComment #17
ndobromirov commentedAs seen in the upstream issue - change in 3.4 will not happen.
Final question I've marked this for Drupal 8.8 but is this viable to happen there or we will be waiting for Drupal 9?
Comment #18
wim leersD'oh, I'd not noticed that. Yep, there's nothing we can do here then right now.
Maybe we can do this in 8.8, but I wouldn't get my hopes up. Related: #2937984: [META] Symfony 4.0 compatibility + #2976394: Allow Symfony 4.4 to be installed in Drupal 8.
Comment #19
ndobromirov commentedFor anyone that might be interested in patching this on 3.4 D8 now, you can try this.
Comment #21
jibranI think this can be un-postponed given #2976394: Allow Symfony 4.4 to be installed in Drupal 8 is almost done. Or should we wait for #3020303: Consider using Symfony flex to allow switching between major Symfony versions?
Whatever we decide the first step should be to collect the benchmark data, IMO.
Comment #22
ndobromirov commentedI think this should be blocked on #3020303: Consider using Symfony flex to allow switching between major Symfony versions...
Comment #25
br0kenLet's start another round here. I'm working on a test to prove the benefit of a patch like this.
Comment #28
wim leers#3252872: Use CacheableSupportsMethodInterface for performance improvement in normalizers landed and basically did what this proposes but only for
jsonapi.module's normalizers.I think we should do the same here now? 🤓
Removing the
[upstream]prefix because it's been fixed upstream, and we're using the updated upstream 👍Comment #29
bbralaI actually fixed all normalizers in core that would support the caching as you can see in this commit.
So i think this one can be closed?
Comment #30
bradjones1Being bold and closing this.
Comment #31
bbralaHehe, you are quicker than me, my personal workflow is wait 2 or 3 weeks for feedback then close it :)
But sure, should be fixed