Skip to content

Add JsonParser.willInternPropertyNames() to check whether property name interning is enabled #1211

Description

@chokoswitch

I have custom deserialization logic of protocol buffers and I took advantage of field names being interned to improve performance.

https://github.com/curioswitch/protobuf-jackson/blob/main/src/main/java/org/curioswitch/common/protobuf/json/ParseSupport.java#L458

Actually, at the time I didn't know it is possible to disable interning. I was able to create a failing test for it

https://github.com/curioswitch/protobuf-jackson/blob/main/src/test/java/org/curioswitch/common/protobuf/json/JacksonInteropTest.java#L20

It would be great to be able to know if the parser is interning to be able to handle this case correctly while also skipping non-reference equality check when it's fine to do so. Currently JsonParser only exposes parser features:

https://fasterxml.github.io/jackson-core/javadoc/2.8/com/fasterxml/jackson/core/JsonParser.html#getFeatureMask()

But there is no access to the factory features. Naturally JsonParser is not the right level for that but I wonder would it be possible to expose factory features from ParserBase? Or it could just be the three standard parser implementations individually exposing it. If we could check the factory features, or more specifically whether the symbol finder is interning strings, then it would be possible to skip .equals for name comparisons.

I looked at databind, and while I'm not completely sure I understand the code, I think this optimization could be applied there too

https://github.com/FasterXML/jackson-databind/blob/2.17/src/main/java/com/fasterxml/jackson/databind/deser/impl/BeanPropertyMap.java#L575

The .equals could be skipped when it's known the fields are interned.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions