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

Excessive String instantiations in NodeType #17

Open
gakesson opened this issue Feb 12, 2020 · 0 comments
Open

Excessive String instantiations in NodeType #17

gakesson opened this issue Feb 12, 2020 · 0 comments

Comments

@gakesson
Copy link

In object allocation profiling the NodeType's method getNodeType is a very frequent allocator of String and StringBuilder object (in our application is is actually one of the dominating allocators). This puts a lot of pressure on the Garbage Collector.

The javac will turn the String concatenation into a StringBuilder and a subsequent toString(), which will always be done even in the most common case that the ret variable is not null.

Proposal is to instead change the NodeType getNodeType method into:

    public static NodeType getNodeType(final JsonNode node)
    {
        final JsonToken token = node.asToken();
        final NodeType ret = TOKEN_MAP.get(token);

        if (ret == null)
        {
            throw new NullPointerException( "unhandled token type " + token);
        }

        return ret;
    }
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

1 participant