Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
#1969728: Implement Field API "field types" as TypedData Plugins needs FieldItem objects to be able to access their own plugin_id and plugin_definition.
The patch over there currently includes this, but it would be best in its own issue IMO.
This was not doable before #1986802: rename PluginInspectionInterface::getDefinition() to getPluginDefinition(), because PluginInspectionInterface had getDefinition(), which clashed with TypedDataInterface's own unrelated getDefinition().
Comment | File | Size | Author |
---|---|---|---|
#14 | TypedData-inspection-2018323-14.patch | 1.13 KB | effulgentsia |
#11 | TypedData-inspection-2018323-11.patch | 7.23 KB | yched |
#11 | interdiff.txt | 7.67 KB | yched |
#8 | TypedData-inspection-2018323-8.patch | 6.86 KB | yched |
#8 | interdiff.txt | 6.29 KB | yched |
Comments
Comment #1
yched CreditAttribution: yched commentedPatch extracted from #1969728: Implement Field API "field types" as TypedData Plugins.
Not sure I caught all the pieces, let's see what the bot thinks.
Note: not sure what to do with LocaleTypedConfig (extends TypedData).
The code that is in charge of instanciating those objects should be modified accordingly, but I don't know where that is.
Doesn't seem to cause test fails though...
Comment #2
yched CreditAttribution: yched commentedTagging
Comment #3
tim.plunkettThis is redundant as Drupal\Component\Plugin\PluginBase already implements PluginInspectionInterface, but I guess it can't hurt.
Comment #3.0
yched CreditAttribution: yched commentedRephrase a bit
Comment #4
yched CreditAttribution: yched commentedTrue. Doesn't hurt, but I guess it's not something we do in other places.
Comment #6
yched CreditAttribution: yched commented#4: TypedData-inspection-2018323-4.patch queued for re-testing.
Comment #7
fagoI must say I'm not in favour of having those generic plugin_id and definition in there. That only makes sense to you when you are exactly clear which plugin this is about, but when someone is working with those classes that's not necessarily the case. (So, yes I can follow the reasoning people don't like generic typed data stuff in their classes - it's the same.)
Cannot we just call it differently here, e.g. $data_type and $type_definition? Or is having $plugin_id & $plugin_definition everywhere the common pattern?
Comment #8
yched CreditAttribution: yched commentedThe params received in __construct() can be named whatever we want.
The only constraint is, if we want to be able to use PluginBase's implementations of getPluginId() / getPluginDefinition(), then we need to place the injected values in $this->pluginId / $this->pluginDefinition class members.
We can also use class members named completely differently, but then we can't extend PluginBase, and need to reimplement PluginInspectionInterface methods ourselves on top of our own property names. I'd rather avoid that, the inconsistency would add confusion IMO.
Updated patch uses the var names proposed in #7.
Comment #9
fagoIn general, that names would work for me. But then, I just realized $data_type is now duplicating $definition['type'].
However, I just realized that this will add two additional object properties to each typed data object, which results in additional memory usage. I don't recall the numbers any more, but I think it was significant :/ A quick check on a patch with loads of entities (300 comments?) would be a good idea I guess.
So, instead of doing that I guess we should come up with an optimized implementation. plugin-id? -> that's equal to getType(). plugin-definition - couldn't we look that up via the manager? We'll have to inject it anyway, as other methods use it already.
Comment #10
yched CreditAttribution: yched commentedThat's how PluginBase::getDefinition() worked until #1875182: Pass plugin definition to plugin instances instead of discovery object. Was hell.
The definition arrays are not physically copied, PHP's copy-on-write optimizes that (and those are never written to, just read from).
Comment #11
yched CreditAttribution: yched commentedRemoves the extraneous $date_type param, and adds custom implementations of PluginInspectionInterface
Comment #12
yched CreditAttribution: yched commentedDevel numbers on a node page with 260 comments:
HEAD: 1172.8 ms. Memory used at: devel_boot()=6.25 MB, devel_shutdown()=21.63 MB, PHP peak=26.25 MB
Patch: 1163.21 ms. Memory used at: devel_boot()=6.26 MB, devel_shutdown()=22 MB, PHP peak=27 MB
That's +1.7% Mem at shutdown, +3% peak
Comment #13
yched CreditAttribution: yched commentedDoh, I was not displaying all the comments.
HEAD: 2759.65 ms. Memory used at: devel_boot()=5.74 MB, devel_shutdown()=46.38 MB, PHP peak=56.25 MB.
Patch: 2727.11 ms. Memory used at: devel_boot()=5.75 MB, devel_shutdown()=47.74 MB, PHP peak=57.75 MB.
+2,9% at shutdown, +2,7% peak
Comment #14
effulgentsia CreditAttribution: effulgentsia commentedSo here's the alternative that I think was suggested in #9. Given that TypedData is already accessing the manager in that way in its other methods, I think this is ok for now. However, like yched, I prefer #11 if fago is ok with it.
I got different numbers than #13 though for a node with ~250 comments viewed as root user. Each run I had to refresh about 3 times before the memory numbers stopped varying:
HEAD:
Page execution time was 5491.79 ms. Memory used at: devel_boot()=4.06 MB, devel_shutdown()=23.68 MB, PHP peak=32 MB.
#11:
Page execution time was 5567.52 ms. Memory used at: devel_boot()=4.07 MB, devel_shutdown()=23.79 MB, PHP peak=32.25 MB.
#14:
Page execution time was 5492.87 ms. Memory used at: devel_boot()=4.07 MB, devel_shutdown()=23.69 MB, PHP peak=32 MB.
So, #14 is a little more performant, but probably only because getPluginDefinition() isn't being called on it yet. That can change with #1969728: Implement Field API "field types" as TypedData Plugins.
In short, I'd be fine with whichever one gets RTBC'd that helps #1969728: Implement Field API "field types" as TypedData Plugins most.
Comment #15
fago#11 has some unnecessary whitespace:
Very interesting comparisons! It's interesting that the results of effulgentsia are better. Maybe, did you use PHP 5.4 vs yched (and me) PHP 5.3 ?
I know - still, it's just the additional object property that results in more memory being used - its content doesn't matter.
I guess that's also because of less stuff being assigned - this code runs through very often. Also, once the manager becomes injected, I don't see a reason to repeat the type definition in the class. We already have problems like #1875182: Pass plugin definition to plugin instances instead of discovery object - but we'll have to solve it at least for the typed data and entity managers in order to inject dependencies into fields and entities anyway.
So - given #14 is simple, faster and uses less memory and we really have to watch performance I think we should go with this one. If field types start using getPluginDefinition() very often, we can still optimize it more.
Thus, I'd call #14 RTBC - if that works for you?
Comment #16
yched CreditAttribution: yched commentedMy tests were done with 5.3, yes.
I'm fine with #14.
(+, #11 still has a @todo that's above my head in LocaleTypedConfig)
But we really need to solve #2004282: Injected dependencies and serialization hell if we intend to actually inject the manager...
Comment #17
yched CreditAttribution: yched commentedRTBC then, #14 is not my patch :-)
Comment #18
effulgentsia CreditAttribution: effulgentsia commentedYay. Glad there's agreement.
Yes, my numbers are for PHP 5.4.10.
Comment #19
alexpottCommitted 94b0b70 and pushed to 8.x. Thanks!
Comment #20.0
(not verified) CreditAttribution: commentedlink to the main issue, not the helper issue