fge / jackson-coreutils

JSON Pointer (RFC 6901) and numeric JSON equivalence for Jackson (2.2.x)
Other
22 stars 31 forks source link

Excessive String instantiations in NodeType #17

Open gakesson opened 4 years ago

gakesson commented 4 years ago

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