Cache for AttributeReader mapping reader #6929

Closed
opened 2026-01-22 15:41:35 +01:00 by admin · 3 comments
Owner

Originally created by @boesing on GitHub (Feb 15, 2022).

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

Hey there,

I do actually miss the AttributeReader cache (there was a cache for the annotations and that safed a hell lot of repeated parsings).
Was there an active decision against such a cached reader?
Is this something to be of interest here?
Is reading from a filesystem cache more performant than using ReflectionClass on entities?
(Haven't made actual benchmarks but from my experience with laminas-hydrator, I do know that using reflection is actually insanely slow)

Would love to get some feedback here and if this is of interest, I'm happy to contribute that cached reader for attributes.

Originally created by @boesing on GitHub (Feb 15, 2022). ### Feature Request <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | New Feature | yes | RFC | yes | BC Break | no #### Summary Hey there, I do actually miss the `AttributeReader` cache (there was a cache for the annotations and that safed a hell lot of repeated parsings). Was there an active decision against such a cached reader? Is this something to be of interest here? Is reading from a filesystem cache more performant than using `ReflectionClass` on entities? (Haven't made actual benchmarks but from my experience with `laminas-hydrator`, I do know that using reflection is actually insanely slow) Would love to get some feedback here and if this is of interest, I'm happy to contribute that cached reader for attributes.
admin added the New Feature label 2026-01-22 15:41:35 +01:00
admin closed this issue 2026-01-22 15:41:35 +01:00
Author
Owner

@derrabus commented on GitHub (Feb 15, 2022):

The cached annotations reader was reasonable because annotations had to be parsed in userland out of an elements doc block.

With attributes, parsing is done by the PHP interpreter itself. Our cache in this case should be PHP's own opcache. Are attributes performing measurably worse than Doctrine Annotations in your case?

@derrabus commented on GitHub (Feb 15, 2022): The cached annotations reader was reasonable because annotations had to be parsed in userland out of an elements doc block. With attributes, parsing is done by the PHP interpreter itself. Our cache in this case should be PHP's own opcache. Are attributes performing measurably worse than Doctrine Annotations in your case?
Author
Owner

@boesing commented on GitHub (Feb 15, 2022):

No, I haven't verified this yet (no benchmarks).
And I think, that it might be less problematic as every class metadata already contains the ReflectionClass and thus the performance impact might not be that huge as I assume.

I just realized performance issues when using ReflectionClass along with laminas-hydrator (ReflectionHydrator) but that was due to the fact that ReflectionClass was called multiple times even tho it was already instantiated in the past. Somehow, this was not cached by opcache (but maybe opcache was disabled in my debugging) and thus lead to performance gaps.
Since the metadata is cached in-memory, the attribute parsing will only happen once and thus I think I would be fine without such a cache in-place.

@boesing commented on GitHub (Feb 15, 2022): No, I haven't verified this yet (no benchmarks). And I think, that it might be less problematic as every class metadata already contains the `ReflectionClass` and thus the performance impact might not be that huge as I assume. I just realized performance issues when using `ReflectionClass` along with `laminas-hydrator` (`ReflectionHydrator`) but that was due to the fact that `ReflectionClass` was called multiple times even tho it was already instantiated in the past. Somehow, this was not cached by opcache (but maybe opcache was disabled in my debugging) and thus lead to performance gaps. Since the metadata is cached in-memory, the attribute parsing will only happen once and thus I think I would be fine without such a cache in-place.
Author
Owner

@derrabus commented on GitHub (Feb 15, 2022):

All right. I'm closing this ticket for now. If you encounter actual performance issues that might be solved by introducing a cache to the reader, feel free to reopen.

@derrabus commented on GitHub (Feb 15, 2022): All right. I'm closing this ticket for now. If you encounter actual performance issues that might be solved by introducing a cache to the reader, feel free to reopen.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6929