Skip to content
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

JSON Contract resolver needs to be reused #954

Open
ProfFrugal opened this issue Aug 12, 2023 · 1 comment
Open

JSON Contract resolver needs to be reused #954

ProfFrugal opened this issue Aug 12, 2023 · 1 comment

Comments

@ProfFrugal
Copy link

JSON Contract resolver is being allocated over and over again, causing more allocation and CPU usage due to reflection and jitting.

For more information: check:

https://www.linkedin.com/feed/update/urn:li:activity:7096144517917016064/
https://frugalcafe.beehiiv.com/p/fc17-real-world-example-not-reusing-json-contract-resolver

@AArnott
Copy link
Member

AArnott commented Aug 14, 2023

Thanks for sharing this. I'm not sure it's as simple as it may look though. We modify the contracts that this DefaultContractResolver object returns in a way that varies based on the instance of the MarshalContractResolver (and in turn, based on the instance of the JsonMessageFormatter). If we were to share a common DefaultContractResolver, the cached contracts would be shared across these instances, and the mutation may corrupt contracts that were previously returned. Such a bug would likely only manifest when multiple threads are actively serializing/deserializing at once, so simple functional tests may not catch it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants