You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many converters currently call expensive reflective operations at execution time, usually while deriving the types for delegation. E.g. when a list is returned, a converter will kick in to apply the conversion on each element. To do this, it first needs to derive the element type from the generic type of the list. This is an easy but expensive operation, performed each time the corresponding field is resolved.
In order to avoid such expensive calls at execution time a new interface is introduced, DelegatingOutputConverter, that declares the getDerivedTypes(AnnotatedType) method. This method will be used to preemptively derive the types at schema initialization time. The result is then cached and made available to the converter via ResolutionEnvironment#getDerived(AnnotatedType) at query execution time. This strategy significantly cuts the performance overhead.
In addition, because the derived types are now known ahead of time, it becomes possible to preemptively prune the list of applicable output converters. This means that only the bare minimum number of converters per field will ever get invoked.
Combined application of these two strategies reduced the performance cost of converters to nearly 0 (as opposed to the current 200% in many cases).
Furthermore, a similar strategy can be employed for input converters, where the types can be derived only during initialization. Since the input converters are wrapped into custom Jackson/Gson deserializers, most of the heavy lifting (e.g. caching) is performed by those libraries, so the optimization work is much easier there. The only semi-significant difference from the case explained above is that with the input converters the type derivation is performed upon the first ever invocation of the converter, not at schema initialization time.
The text was updated successfully, but these errors were encountered:
Continuing the work from #194.
Many converters currently call expensive reflective operations at execution time, usually while deriving the types for delegation. E.g. when a list is returned, a converter will kick in to apply the conversion on each element. To do this, it first needs to derive the element type from the generic type of the list. This is an easy but expensive operation, performed each time the corresponding field is resolved.
In order to avoid such expensive calls at execution time a new interface is introduced,
DelegatingOutputConverter
, that declares thegetDerivedTypes(AnnotatedType)
method. This method will be used to preemptively derive the types at schema initialization time. The result is then cached and made available to the converter viaResolutionEnvironment#getDerived(AnnotatedType)
at query execution time. This strategy significantly cuts the performance overhead.In addition, because the derived types are now known ahead of time, it becomes possible to preemptively prune the list of applicable output converters. This means that only the bare minimum number of converters per field will ever get invoked.
Combined application of these two strategies reduced the performance cost of converters to nearly 0 (as opposed to the current 200% in many cases).
Furthermore, a similar strategy can be employed for input converters, where the types can be derived only during initialization. Since the input converters are wrapped into custom Jackson/Gson deserializers, most of the heavy lifting (e.g. caching) is performed by those libraries, so the optimization work is much easier there. The only semi-significant difference from the case explained above is that with the input converters the type derivation is performed upon the first ever invocation of the converter, not at schema initialization time.
The text was updated successfully, but these errors were encountered: