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

performance: don't parse all numbers as BigDecimal #1121

Open
pjfanning opened this issue Jan 11, 2025 · 1 comment
Open

performance: don't parse all numbers as BigDecimal #1121

pjfanning opened this issue Jan 11, 2025 · 1 comment

Comments

@pjfanning
Copy link
Contributor

JsNumber wraps a BigDecimal. Parsing BigDecimals is expensive. Converting BigDecimals to other number formats later on is expensive - especially to BigInteger (some edge cases have terrible performance).

For me, the ideal is that if you are binding to case class that needs the number as a Long that you parse the number as a Long and not as BigDecimal that later is converted to a Long.

It would need to go into a major version release but I think it would be worth considering having play-json parser create JsNumbers or a new JsLazyNumber that starts with the number in string format avoiding the number parsing overhead early on. The Reads code would parse the Longs/Ints/BigDecimals/etc/ from the String representation of the number.

It's possible that some numbers that are in the JSON input may not be needed when binding to an object instance - so the number won't have to be parsed at all.

Reading

Is the thinking that play-json-jsoniter is the best way to improve performance? I think that play-json-jsoniter can also benefit from avoiding BigDecimals where they are not needed.

@plokhotnyuk
Copy link

plokhotnyuk commented Jan 11, 2025

A better option would be using smithy4play then all routes, data structures, codecs (that will use jsoniter-scala under the hood, see smithy4sJson labeled results here) and API docs for all that will be automatically generated from service definitions written in Smithy IDL. If you will share your definitions with users of your API then they can reuse them for generation of clients even in TypeScript.

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