Repository navigation
Generate class transformers ahead of time - #218
Open
DavidBadura wants to merge 1 commit into
Open
DavidBadura wants to merge 1 commit into
DavidBadura wants to merge 1 commit into
Conversation
The GeneratedTransformerExtension registers a transformer factory which loads generated code instead of using reflection. Code is never generated at runtime: the factory only requires files the GeneratedTransformerWarmer wrote beforehand and falls back to reflection if there is none. An architecture test makes sure the runtime classes do not depend on the generation. The file name contains the fingerprints of the class and its nested classes, so changed classes simply fall back to reflection until the next warmup. Nested objects are inlined if no middleware runs for them, unless the hydrator was wrapped by another one. The StackHydrator now implements MetadataFactory and exposes its middlewares and the default lazy flag, which is all a transformer factory needs. The call stack for circular references moved into the context.
|
Hello 👋 here is the most recent benchmark result:
This comment gets update everytime a new commit comes in! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings the code generation from #150 / #214 to 3.0, on top of the transformer factories from #217.
GeneratedTransformerExtensionregisters aClassTransformerFactorywhich loads a generated transformer per class instead of using reflection. Code is never generated at runtime: the factory only requires files that exist and otherwise returns null, so the class falls back to reflection. The code is written beforehand by theGeneratedTransformerWarmer, for example on deploy:A new PHPat rule (
NoCodeGenerationAtRuntimeTest) makes sure the runtime classes (extension, factory,TransformerFiles,ClassFingerprint) never depend on the generator, so this can't creep back in.Compared to #214:
$context[Hydrator::HYDRATOR], so a hydrator which wraps theStackHydratorstill sees nested objects.ClassTransformerFactory::create()now also gets theStackHydrator, which got the gettersmiddlewares()anddefaultLazy()and implementsMetadataFactory. The warmer takes it as metadata factory, so there is no extra builder method or adapter.HydratorAwareNormalizeris gone, the generated code treats every normalizer as possibly calling the hydrator again, except the built-in enum and date normalizers. That only decides whether circular references are tracked.Benchmarks on this branch (PHP 8.5, opcache, xdebug off), reflection vs generated:
The generated benchmarks run the warmup once per class via
BeforeClassMethodsinstead of in every iteration.