playframework / playframework/play-json
performance: don't parse all numbers as BigDecimal
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 375
- Forks
- 140
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 28
Description
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
- https://github.com/wrandelshofer/FastDoubleParser
- https://plokhotnyuk.github.io/jsoniter-scala/ (shows play-json a bit behind in perf)
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the parser implementation and the Reads code in play-json/shared/src/main/scala/play/api/libs/json/Reads.scala. Compare the proposed lazy or type-directed number handling with FastDoubleParser and jsoniter-scala, then establish benchmarks and compatibility requirements. Done would mean an agreed design and demonstrated performance improvement without breaking numeric Reads behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100