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/07/24 11:59:00 UTC

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

    [ https://issues.apache.org/jira/browse/OAK-10972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17868346#comment-17868346 ] 

Julian Reschke commented on OAK-10972:
--------------------------------------

Not completely convinced. How many properties of type "DOUBLE" do we have in practice?

> 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: store-spi
>            Reporter: Nuno Santos
>            Priority: Minor
>
> 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)