Skip to content

feat: kotlinx serialization for GraphQLServerRequest -- cherry pick (#1937) #1944

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

Merged
merged 6 commits into from
Apr 1, 2024

Conversation

samuelAndalon
Copy link
Contributor

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 image

GraphQLRequest
image

GraphQLBatchResponse
image

GraphQLResponse
image

📝 Description

🔗 Related Issues

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">
@samuelAndalon samuelAndalon enabled auto-merge (squash) April 1, 2024 23:25
@samuelAndalon samuelAndalon requested a review from Samjin April 1, 2024 23:26
@samuelAndalon samuelAndalon merged commit 65aa3f0 into 6.x.x Apr 1, 2024
@samuelAndalon samuelAndalon deleted the feat/6.x.x/server-kotlinx-serialization branch April 1, 2024 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants