Skip to content

Excessive String instantiations in NodeType #17

Description

@gakesson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions