Skip to content

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

@pjfanning

Description

@pjfanning

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions