Skip to content

Add groups extension - #211

Open
DavidBadura wants to merge 1 commit into
2.1.xfrom
groups-extension
Open

DavidBadura wants to merge 1 commit into
2.1.xfrom
groups-extension

Conversation

@DavidBadura

@DavidBadura DavidBadura commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

This adds a GroupsExtension for serialization groups. Properties are tagged with the new #[Groups] attribute and the groups are selected per call with GroupsExtension::GROUPS in the context. GroupsExtension::IGNORED_GROUPS does the opposite and excludes properties of the given groups.

Without groups in the context everything is used, once groups are selected properties without the attribute are left out, and * selects everything. The context is passed on, so nested objects are filtered as well, which also allows breaking circular references by putting the back reference into another group.

On extract the middleware hands a filtered ClassMetadata to the next middleware, so excluded properties are never read. On hydrate it drops the excluded fields from the data, so promoted defaults still apply. Filtered metadata is cached per class and group selection, and the middleware returns early when no groups are in the context.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Hello 👋

here is the most recent benchmark result:

StackHydratorBench
==================

+-------------------------------+-------------------------------------+------------------------------+
|                               | time (kde mode)                     | memory                       |
+-------------------------------+------------------+------------------+-----------------+------------+
| subject                       | Tag: <current>   | Tag: base        | Tag: <current>  | Tag: base  |
+-------------------------------+------------------+------------------+-----------------+------------+
| benchHydrate1Object ()        | 4.000μs (±0.00%) | 3.800μs (±0.00%) | 2.772mb         | 3.296mb    |
| benchExtract1Object ()        | 4.000μs (±0.00%) | 3.600μs (±0.00%) | 2.772mb         | 3.296mb    |
| benchHydrate1000Objects ()    | 2.594ms (±0.00%) | 2.589ms (±0.00%) | 3.019mb         | 3.019mb    |
| benchExtract1000Objects ()    | 2.480ms (±0.00%) | 2.432ms (±0.00%) | 3.008mb         | 3.008mb    |
| benchHydrate1000000Objects () | 1.442s (±0.00%)  | 1.491s (±0.00%)  | 3.019mb         | 3.019mb    |
| benchExtract1000000Objects () | 1.540s (±0.00%)  | 1.521s (±0.00%)  | 3.009mb         | 3.009mb    |
+-------------------------------+------------------+------------------+-----------------+------------+

HydratorWithLazyBench
=====================

+------------------------------------------+-----------------------------------------+------------------------------+
|                                          | time (kde mode)                         | memory                       |
+------------------------------------------+--------------------+--------------------+-----------------+------------+
| subject                                  | Tag: <current>     | Tag: base          | Tag: <current>  | Tag: base  |
+------------------------------------------+--------------------+--------------------+-----------------+------------+
| benchHydrate1Object ()                   | 1.000μs (±0.00%)   | 0.800μs (±0.00%)   | 2.772mb         | 2.772mb    |
| benchHydrate1ObjectTriggerInit ()        | 4.800μs (±0.00%)   | 4.200μs (±0.00%)   | 2.772mb         | 2.772mb    |
| benchHydrate1000Objects ()               | 449.000μs (±0.00%) | 447.667μs (±0.00%) | 2.817mb         | 2.817mb    |
| benchHydrate1000ObjectsTriggerInit ()    | 3.380ms (±0.00%)   | 3.378ms (±0.00%)   | 2.931mb         | 2.931mb    |
| benchHydrate1000000Objects ()            | 297.062ms (±0.00%) | 301.500ms (±0.00%) | 2.817mb         | 2.817mb    |
| benchHydrate1000000ObjectsTriggerInit () | 2.168s (±0.00%)    | 2.127s (±0.00%)    | 2.931mb         | 2.931mb    |
+------------------------------------------+--------------------+--------------------+-----------------+------------+

StackHydratorWithCryptographyBench
==================================

+-------------------------------+---------------------------------------+------------------------------+
|                               | time (kde mode)                       | memory                       |
+-------------------------------+-------------------+-------------------+-----------------+------------+
| subject                       | Tag: <current>    | Tag: base         | Tag: <current>  | Tag: base  |
+-------------------------------+-------------------+-------------------+-----------------+------------+
| benchHydrate1Object ()        | 7.800μs (±0.00%)  | 7.200μs (±0.00%)  | 2.820mb         | 2.820mb    |
| benchExtract1Object ()        | 79.200μs (±0.00%) | 80.200μs (±0.00%) | 2.836mb         | 2.836mb    |
| benchHydrate1000Objects ()    | 4.280ms (±0.00%)  | 4.210ms (±0.00%)  | 3.115mb         | 3.115mb    |
| benchExtract1000Objects ()    | 8.970ms (±0.00%)  | 8.975ms (±0.00%)  | 3.203mb         | 3.203mb    |
| benchHydrate1000000Objects () | 2.275s (±0.00%)   | 2.260s (±0.00%)   | 3.115mb         | 3.115mb    |
| benchExtract1000000Objects () | 6.674s (±0.00%)   | 6.643s (±0.00%)   | 3.201mb         | 3.201mb    |
+-------------------------------+-------------------+-------------------+-----------------+------------+

HydratorBench
=============

+-------------------------------+-------------------------------------+------------------------------+
|                               | time (kde mode)                     | memory                       |
+-------------------------------+------------------+------------------+-----------------+------------+
| subject                       | Tag: <current>   | Tag: base        | Tag: <current>  | Tag: base  |
+-------------------------------+------------------+------------------+-----------------+------------+
| benchHydrate1Object ()        | 3.800μs (±0.00%) | 3.400μs (±0.00%) | 2.772mb         | 2.772mb    |
| benchExtract1Object ()        | 4.000μs (±0.00%) | 3.800μs (±0.00%) | 2.772mb         | 2.772mb    |
| benchHydrate1000Objects ()    | 2.600ms (±0.00%) | 2.571ms (±0.00%) | 3.019mb         | 3.019mb    |
| benchExtract1000Objects ()    | 2.423ms (±0.00%) | 2.448ms (±0.00%) | 3.008mb         | 3.008mb    |
| benchHydrate1000000Objects () | 1.452s (±0.00%)  | 1.463s (±0.00%)  | 3.019mb         | 3.019mb    |
| benchExtract1000000Objects () | 1.537s (±0.00%)  | 1.543s (±0.00%)  | 3.009mb         | 3.009mb    |
+-------------------------------+------------------+------------------+-----------------+------------+

HydratorWithCryptographyBench
=============================

+-------------------------------+---------------------------------------+------------------------------+
|                               | time (kde mode)                       | memory                       |
+-------------------------------+-------------------+-------------------+-----------------+------------+
| subject                       | Tag: <current>    | Tag: base         | Tag: <current>  | Tag: base  |
+-------------------------------+-------------------+-------------------+-----------------+------------+
| benchHydrate1Object ()        | 7.200μs (±0.00%)  | 11.400μs (±0.00%) | 2.820mb         | 2.820mb    |
| benchExtract1Object ()        | 78.400μs (±0.00%) | 79.200μs (±0.00%) | 2.836mb         | 2.836mb    |
| benchHydrate1000Objects ()    | 4.239ms (±0.00%)  | 4.222ms (±0.00%)  | 3.114mb         | 3.114mb    |
| benchExtract1000Objects ()    | 8.850ms (±0.00%)  | 9.032ms (±0.00%)  | 3.203mb         | 3.203mb    |
| benchHydrate1000000Objects () | 2.249s (±0.00%)   | 2.248s (±0.00%)   | 3.115mb         | 3.115mb    |
| benchExtract1000000Objects () | 6.630s (±0.00%)   | 6.693s (±0.00%)   | 3.201mb         | 3.201mb    |
+-------------------------------+-------------------+-------------------+-----------------+------------+

This comment gets update everytime a new commit comes in!

@DavidBadura DavidBadura added this to the 2.1.0 milestone Oct 2, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Oct 2, 2026
Properties can be assigned to groups with the new Groups attribute and
selected or excluded per call via the groups and ignored_groups context
keys. Filtering applies to extract and hydrate and is passed on to nested
objects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant