-
Notifications
You must be signed in to change notification settings - Fork 348
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
feat: kotlinx serialization for GraphQLServerRequest #1937
feat: kotlinx serialization for GraphQLServerRequest #1937
Conversation
servers/graphql-kotlin-server/src/benchmarks/kotlin/testtypes/GraphQLServerError.kt
Outdated
Show resolved
Hide resolved
… into feat/serialization-benchmarks
… into feat/serialization-benchmarks
Important to mention that Ktor server will still use jackson as engine for deserialization: Spring webflux server will use kotlinx as if server detects both set of annotations jackson, kotlinx, will use kotlinx. In a separate PR we can make this configurable. |
Switch from `jackson` to `kotlinx.serialization` for serialization/deserialization of `GraphQLServerRequest` types. After running benchmarks we where able to identify that deserializing `GraphQLServerRequest` with `kotlinx.serialization` is quite faster than doing it with `jackson`, the reason ? possibly because jackson relies on reflections to identify deserialization process. On the other hand, serialization/deserialization of `GraphQLServerReponse` type is still faster if done with `jackson`, possibly because of how `kotlinx.serialization` library was designed and the poor support for serializing `Any` type: Kotlin/kotlinx.serialization#296, which causes a lot of memory comsumption. As part of this PR also including the benchmarks. For that, i created a separate set of types that are marked with both `jackson` and `kotlinx.serialization` annotations. Benchmarks results: Executed on a MacBookPro 2.6 GHz 6-Core Intel Core i7. `GraphQLBatchRequest` 4 batched operations, each operation is aprox: 30kb <img width="1260" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/06e5b218-a35e-4baa-a25e-2be1b3c27a95"> `GraphQLRequest` <img width="1231" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/e5ecba01-fd41-4872-b3e8-5519414cc918"> `GraphQLBatchResponse` <img width="1240" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/ee84bfa4-d7d1-46b4-b4a8-b3c220998a03"> `GraphQLResponse` <img width="1197" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/c217e05f-45fc-460e-a059-7667975ee49f">
…1937) (#1944) Switch from `jackson` to `kotlinx.serialization` for serialization/deserialization of `GraphQLServerRequest` types. After running benchmarks we where able to identify that deserializing `GraphQLServerRequest` with `kotlinx.serialization` is quite faster than doing it with `jackson`, the reason ? possibly because jackson relies on reflections to identify deserialization process. On the other hand, serialization/deserialization of `GraphQLServerReponse` type is still faster if done with `jackson`, possibly because of how `kotlinx.serialization` library was designed and the poor support for serializing `Any` type: Kotlin/kotlinx.serialization#296, which causes a lot of memory comsumption. As part of this PR also including the benchmarks. For that, i created a separate set of types that are marked with both `jackson` and `kotlinx.serialization` annotations. Benchmarks results: Executed on a MacBookPro 2.6 GHz 6-Core Intel Core i7. `GraphQLBatchRequest` 4 batched operations, each operation is aprox: 30kb <img width="1260" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/06e5b218-a35e-4baa-a25e-2be1b3c27a95"> `GraphQLRequest` <img width="1231" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/e5ecba01-fd41-4872-b3e8-5519414cc918"> `GraphQLBatchResponse` <img width="1240" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/ee84bfa4-d7d1-46b4-b4a8-b3c220998a03"> `GraphQLResponse` <img width="1197" alt="image" src="https://github.com/ExpediaGroup/graphql-kotlin/assets/6611331/c217e05f-45fc-460e-a059-7667975ee49f"> ### 📝 Description ### 🔗 Related Issues
…ion of GraphQLRequest (#2040) ### 📝 Description [the previous integration of kotlinx-serialization](#1937) represented a performance improvement when deserializing requests, however, responses are still being deserialized with jackson, recently we found that fastjson2 is the [fastest serialization library for the jvm](https://github.com/fabienrenaud/java-json-benchmark). this PR adds an opt-in support for fastjson2 which provides an easy integration with springboot codecs, the serializer relies on the same jackson annotation, and just had to write a deserializer because of the polymorphic nature of GraphQLRequest and GraphQLReponse #### benchmark results GraphQLRequest deserialization <img width="1156" alt="image" src="https://github.com/user-attachments/assets/8a1e56a2-0d6f-4118-904a-a5d584caac19"> GraphQLResponse serialization <img width="1161" alt="image" src="https://github.com/user-attachments/assets/cfa6c843-50de-42e2-8f8e-7722c722b048"> --------- Co-authored-by: Samuel Vazquez <[email protected]>
…ion of GraphQLRequest (#2040) [the previous integration of kotlinx-serialization](#1937) represented a performance improvement when deserializing requests, however, responses are still being deserialized with jackson, recently we found that fastjson2 is the [fastest serialization library for the jvm](https://github.com/fabienrenaud/java-json-benchmark). this PR adds an opt-in support for fastjson2 which provides an easy integration with springboot codecs, the serializer relies on the same jackson annotation, and just had to write a deserializer because of the polymorphic nature of GraphQLRequest and GraphQLReponse GraphQLRequest deserialization <img width="1156" alt="image" src="https://github.com/user-attachments/assets/8a1e56a2-0d6f-4118-904a-a5d584caac19"> GraphQLResponse serialization <img width="1161" alt="image" src="https://github.com/user-attachments/assets/cfa6c843-50de-42e2-8f8e-7722c722b048"> --------- Co-authored-by: Samuel Vazquez <[email protected]>
📝 Description
Switch from
jackson
tokotlinx.serialization
for serialization/deserialization ofGraphQLServerRequest
types.After running benchmarks we where able to identify that deserializing
GraphQLServerRequest
withkotlinx.serialization
is quite faster than doing it withjackson
, the reason ? possibly because jackson relies on reflections to identify deserialization process.On the other hand, serialization/deserialization of
GraphQLServerReponse
type is still faster if done withjackson
, possibly because of howkotlinx.serialization
library was designed and the poor support for serializingAny
type:Kotlin/kotlinx.serialization#296, which causes a lot of memory comsumption.
As part of this PR also including the benchmarks. For that, i created a separate set of types that are marked with both
jackson
andkotlinx.serialization
annotations.Benchmarks results:
Executed on a MacBookPro 2.6 GHz 6-Core Intel Core i7.
GraphQLServerRequest Deserialization
GraphQLBatchRequest
4 batched operations, each operation is aprox: 30kb
GraphQLRequest
GraphQLServerResponse Serialization
GraphQLBatchResponse
GraphQLResponse