-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Serializer] Document CompiledClassMetadataFactory #10706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
…ault) This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [Serializer] Add CompiledClassMetadataFactory | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ? | License | MIT | Doc PR | todo (issue: symfony/symfony-docs#10706) This introduce a dumped `ClassMetadataFactoryInterface` implementation to speed up the serializer by leveraging [PHP7 immutable array](https://blog.blackfire.io/php-7-performance-improvements-immutable-arrays.html). Like for #28865, if the user have the opcache extension enabled, the compilation time will be skipped. The user will also have a performance boost when not using opcache as we are no longer fetching `ClassMetadata` from the PSR-6 cache. This allow to speed up the normalization (without opcache) by 9-12% depending on how many objects are involved in the graph: - [SymfonyObjectNormalizerBenchmark, 100 iterations with complexity of 1](https://blackfire.io/profiles/compare/d937a9cc-eebf-47eb-be90-c8e65cdf12b3/graph) - [SymfonyObjectNormalizerBenchmark, 3 iterations with complexity of 60](https://blackfire.io/profiles/compare/d490542c-9a79-48a0-b7bc-1ed3ca6a9148/graph) On the `FrameworkBundle` side, I suggest to add a `CacheWarmer` to dump the metadata array from configured class list. The list could have a _good_ default which will load the classes found in `src/Entity`. ## Dumping the `ClassMetadata` ```php $classMetadatas = []; foreach([Category::class, Comment::class, Forum::class, Thread::class, User::class] as $class) { $classMetadatas[] = $this->classMetadataFactory->getMetadataFor($class); } file_put_contents('dumped.php', $this->classMetadataFactoryCompiler->compile($classMetadatas)); ``` ## Using the dumped `ClassMetadata` ```php $classMetadataFactory = new CompiledClassMetadataFactory( 'dumped.php', new CacheClassMetadataFactory( new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())), new ApcuAdapter('SymfonyMetadata') ) ); ``` # To do - [x] Tests. - [x] Cache warmer. - [x] Documentation. - [x] Changelog entry. Commits ------- 63cbf0a [Serializer] Add CompiledClassMetadataFactory
Thank you for this issue. |
Friendly reminder that this issue exists. If I don't hear anything I'll close this. |
Don't close it |
Thank you for this issue. |
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3 |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
I don't know how to document this feature. Should it be documented at the component level or should I wait the framework integration?
PR: symfony/symfony#29117
The text was updated successfully, but these errors were encountered: