You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Julian Reschke (Jira)" <ji...@apache.org> on 2024/10/08 20:07:00 UTC

[jira] (OAK-10972) JsonDeserializer: do not rely on NumberFormatExceptions in the common case when parsing doubles

    [ https://issues.apache.org/jira/browse/OAK-10972 ]


    Julian Reschke deleted comment on OAK-10972:
    --------------------------------------

was (Author: reschke):
trunk: (1.70.0) (1.68.0) [4209b8b3a3|https://github.com/apache/jackrabbit-oak/commit/4209b8b3a36fbcfc72a5cea3548ed4c51409f211]

> JsonDeserializer: do not rely on NumberFormatExceptions in the common case when parsing doubles
> -----------------------------------------------------------------------------------------------
>
>                 Key: OAK-10972
>                 URL: https://issues.apache.org/jira/browse/OAK-10972
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: documentmk, store-spi
>            Reporter: Nuno Santos
>            Priority: Minor
>             Fix For: 1.68.0
>
>
> The current logic first tries to parse numbers as Long, catching a NumberFormatException if that fails and then parsing them as double.
> {code}
> try {
>     type = PropertyType.LONG;
>     values.add(Long.parseLong(number));
> } catch (NumberFormatException e) {
>     type = PropertyType.DOUBLE;
>     values.add(Double.parseDouble(number));
> }
> {code}
> This is very expensive because creating an exception requires capturing the stack trace. In a benchmark that iterates over 10 million json strings representing the contents of a typical Oak repository, an alternative implementation that does not rely on exceptions is almost 30% faster:
> - current logic:  70s
> - parser without exceptions: 50s 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)