-
-
Notifications
You must be signed in to change notification settings - Fork 21
Converter performance #526
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
base: main
Are you sure you want to change the base?
Conversation
packages/Ecotone/src/Messaging/Conversion/SerializedToObject/DeserializingConverter.php
Outdated
Show resolved
Hide resolved
packages/Ecotone/src/Messaging/Conversion/AutoCollectionConversionService.php
Show resolved
Hide resolved
81f3e67
to
0248416
Compare
if ($conversionService === null) { | ||
throw ConversionException::create("To convert serialized data to different type than original, you need to set conversion service in " . self::class); | ||
} | ||
return $conversionService->convert($phpVar, Type::createFromVariable($phpVar), MediaType::createApplicationXPHP(), $targetType, MediaType::createApplicationXPHP()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea behind convert method
was to be called, when we know that given Converter can handle conversion, however it feels now that it may be called regardless and require fallback.
Can you explain that design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard for me to see the connection between this and static converters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you remember the double conversion code ? It has been replaced by this snippet.
This is really only for the deserializing converter.
Imagine I have an array ["status" => "done"]
that is serialized by the serializing converter.
Now, if I am asking for this to be deseriliazed to the Status
enum, the deserializing converter would give me an array instead. This is why we need to denormalize further. Does it makes sense ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard for me to see the connection between this and static converters
This has nothin to do with static converters, it is another PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imagine I have an array ["status" => "done"] that is serialized by the serializing converter.
Now, if I am asking for this to be deseriliazed to the Status enum, the deserializing converter would give me an array instead. This is why we need to denormalize further. Does it makes sense ?
Yep, thanks for explaining :)
If we want to do it in Deserializing only, can we then inject ConversionService to this DeserializingConverter
(as part of DI), instead of changing the API (interface)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to do it in Deserializing only, can we then inject ConversionService to this DeserializingConverter (as part of DI), instead of changing the API (interface)?
We would have a circular dependency(ConversionService
depends on DeserializingConverter
which depends on ConversionService
). Maybe it is possible now with lazy services features provided my modern dependency injection, but It requires at least some work in EcotoneLite container implementation.
$converted = $converter->convert($source, $sourcePHPType, $sourceMediaType, $targetPHPType, $targetMediaType); | ||
$convertedType = Type::createFromVariable($converted); | ||
// Some converters (eg. DeserializingConverter) may return a value that is not compatible with the target type, | ||
// so we try to convert it again, from the new media type and PHP type. | ||
if (! $convertedType->isCompatibleWith($targetPHPType) && $targetMediaType->isCompatibleWith(MediaType::createApplicationXPHP())) { | ||
$sourceMediaType = MediaType::createApplicationXPHPWithTypeParameter($convertedType->getTypeHint()); | ||
$converter = $this->getConverter($convertedType, $sourceMediaType, $targetPHPType, $targetMediaType); | ||
if (is_object($converter)) { | ||
$converted = $converter->convert($converted, $convertedType, $sourceMediaType, $targetPHPType, $targetMediaType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the "double conversion" code, which was here only for deserializing converter
Why is this change proposed?
For conversion performance
Description of Changes
This PR will cache converter resolution
Pull Request Contribution Terms