Skip to content

Add context attribute for properties - #212

Draft
DavidBadura wants to merge 1 commit into
2.1.xfrom
context-attribute
Draft

DavidBadura wants to merge 1 commit into
2.1.xfrom
context-attribute

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

This adds a #[Context] attribute to set context for a single property. It is merged into the context passed to the normalizer of that property and on to nested objects, with values from the attribute taking precedence over the context of the call. The attribute is repeatable, multiple contexts are merged in order.

DateTimeImmutableNormalizer and DateTimeNormalizer now read the format from the datetime_format context key (::FORMAT), which overrides the format given to the normalizer. Together with the attribute this allows a different date format per property, or per call.

PropertyMetadata gets a new context field. Metadata cached by an older version is still loaded and falls back to an empty context. Properties without the attribute only add an empty array check to the hot path, and when the call has no context the property context is passed on directly without merging.

The new Context attribute adds context for a single property, which is
merged into the context passed to its normalizer and on to nested
objects. The date normalizers can now take their format from the context
via the datetime_format key.
@DavidBadura
DavidBadura marked this pull request as draft October 2, 2026 21:17
@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 ()        | 5.600μs (±0.00%) | 2.600μs (±0.00%) | 2.772mb         | 3.296mb    |
| benchExtract1Object ()        | 2.800μs (±0.00%) | 3.000μs (±0.00%) | 2.772mb         | 3.296mb    |
| benchHydrate1000Objects ()    | 2.092ms (±0.00%) | 1.992ms (±0.00%) | 3.019mb         | 3.500mb    |
| benchExtract1000Objects ()    | 1.869ms (±0.00%) | 1.829ms (±0.00%) | 3.008mb         | 3.490mb    |
| benchHydrate1000000Objects () | 1.021s (±0.00%)  | 1.009s (±0.00%)  | 3.019mb         | 3.500mb    |
| benchExtract1000000Objects () | 1.035s (±0.00%)  | 1.067s (±0.00%)  | 3.009mb         | 3.009mb    |
+-------------------------------+------------------+------------------+-----------------+------------+

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

+------------------------------------------+-----------------------------------------+------------------------------+
|                                          | time (kde mode)                         | memory                       |
+------------------------------------------+--------------------+--------------------+-----------------+------------+
| subject                                  | Tag: <current>     | Tag: base          | Tag: <current>  | Tag: base  |
+------------------------------------------+--------------------+--------------------+-----------------+------------+
| benchHydrate1Object ()                   | 0.600μs (±0.00%)   | 0.600μs (±0.00%)   | 2.772mb         | 2.772mb    |
| benchHydrate1ObjectTriggerInit ()        | 3.000μs (±0.00%)   | 3.000μs (±0.00%)   | 2.772mb         | 2.772mb    |
| benchHydrate1000Objects ()               | 330.667μs (±0.00%) | 332.667μs (±0.00%) | 2.817mb         | 2.817mb    |
| benchHydrate1000ObjectsTriggerInit ()    | 2.489ms (±0.00%)   | 2.456ms (±0.00%)   | 2.931mb         | 2.931mb    |
| benchHydrate1000000Objects ()            | 193.023ms (±0.00%) | 196.981ms (±0.00%) | 2.817mb         | 2.817mb    |
| benchHydrate1000000ObjectsTriggerInit () | 1.422s (±0.00%)    | 1.459s (±0.00%)    | 2.931mb         | 2.931mb    |
+------------------------------------------+--------------------+--------------------+-----------------+------------+

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

+-------------------------------+----------------------------------------+------------------------------+
|                               | time (kde mode)                        | memory                       |
+-------------------------------+--------------------+-------------------+-----------------+------------+
| subject                       | Tag: <current>     | Tag: base         | Tag: <current>  | Tag: base  |
+-------------------------------+--------------------+-------------------+-----------------+------------+
| benchHydrate1Object ()        | 343.600μs (±0.00%) | 8.400μs (±0.00%)  | 3.115mb         | 2.820mb    |
| benchExtract1Object ()        | 41.800μs (±0.00%)  | 73.000μs (±0.00%) | 2.820mb         | 2.836mb    |
| benchHydrate1000Objects ()    | 3.249ms (±0.00%)   | 3.301ms (±0.00%)  | 3.115mb         | 3.115mb    |
| benchExtract1000Objects ()    | 6.569ms (±0.00%)   | 6.828ms (±0.00%)  | 3.201mb         | 3.203mb    |
| benchHydrate1000000Objects () | 1.533s (±0.00%)    | 1.588s (±0.00%)   | 3.115mb         | 3.115mb    |
| benchExtract1000000Objects () | 4.672s (±0.00%)    | 4.803s (±0.00%)   | 3.201mb         | 3.201mb    |
+-------------------------------+--------------------+-------------------+-----------------+------------+

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

+-------------------------------+-------------------------------------+------------------------------+
|                               | time (kde mode)                     | memory                       |
+-------------------------------+------------------+------------------+-----------------+------------+
| subject                       | Tag: <current>   | Tag: base        | Tag: <current>  | Tag: base  |
+-------------------------------+------------------+------------------+-----------------+------------+
| benchHydrate1Object ()        | 2.600μs (±0.00%) | 2.600μs (±0.00%) | 2.772mb         | 2.772mb    |
| benchExtract1Object ()        | 3.000μs (±0.00%) | 2.600μs (±0.00%) | 2.772mb         | 2.772mb    |
| benchHydrate1000Objects ()    | 2.008ms (±0.00%) | 2.012ms (±0.00%) | 3.019mb         | 3.019mb    |
| benchExtract1000Objects ()    | 1.876ms (±0.00%) | 1.868ms (±0.00%) | 3.008mb         | 3.008mb    |
| benchHydrate1000000Objects () | 1.020s (±0.00%)  | 1.014s (±0.00%)  | 3.019mb         | 3.019mb    |
| benchExtract1000000Objects () | 1.034s (±0.00%)  | 1.066s (±0.00%)  | 3.009mb         | 3.009mb    |
+-------------------------------+------------------+------------------+-----------------+------------+

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

+-------------------------------+----------------------------------------+------------------------------+
|                               | time (kde mode)                        | memory                       |
+-------------------------------+--------------------+-------------------+-----------------+------------+
| subject                       | Tag: <current>     | Tag: base         | Tag: <current>  | Tag: base  |
+-------------------------------+--------------------+-------------------+-----------------+------------+
| benchHydrate1Object ()        | 340.000μs (±0.00%) | 5.000μs (±0.00%)  | 3.114mb         | 2.820mb    |
| benchExtract1Object ()        | 41.200μs (±0.00%)  | 72.000μs (±0.00%) | 2.820mb         | 2.836mb    |
| benchHydrate1000Objects ()    | 3.219ms (±0.00%)   | 3.333ms (±0.00%)  | 3.114mb         | 3.114mb    |
| benchExtract1000Objects ()    | 6.589ms (±0.00%)   | 6.802ms (±0.00%)  | 3.201mb         | 3.203mb    |
| benchHydrate1000000Objects () | 1.536s (±0.00%)    | 1.585s (±0.00%)   | 3.115mb         | 3.115mb    |
| benchExtract1000000Objects () | 4.796s (±0.00%)    | 4.789s (±0.00%)   | 3.201mb         | 3.201mb    |
+-------------------------------+--------------------+-------------------+-----------------+------------+

This comment gets update everytime a new commit comes in!

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.

1 participant