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

Reduce allocations due to Jackson serialization. #12468

Merged
merged 3 commits into from
Apr 27, 2022

Conversation

gianm
Copy link
Contributor

@gianm gianm commented Apr 21, 2022

This patch attacks two sources of allocations during Jackson
serialization:

  1. ObjectMapper.writeValue and JsonGenerator.writeObject create a new
    DefaultSerializerProvider instance for each call. It has lots of
    fields and creates pressure on the garbage collector. So, this patch
    adds helper functions in JacksonUtils that enable reuse of
    SerializerProvider objects and updates various call sites to make
    use of this.

  2. GroupByQueryToolChest copies the ObjectMapper for every query to
    install a special module that supports backwards compatibility with
    map-based rows. This isn't needed if resultAsArray is set and
    all servers are running Druid 0.16.0 or later. This release was a
    while ago. So, this patch disables backwards compatibility by default,
    which eliminates the need to copy the heavyweight ObjectMapper. The
    patch also introduces a configuration option that allows admins to
    explicitly enable backwards compatibility.

This patch attacks two sources of allocations during Jackson
serialization:

1) ObjectMapper.writeValue and JsonGenerator.writeObject create a new
   DefaultSerializerProvider instance for each call. It has lots of
   fields and creates pressure on the garbage collector. So, this patch
   adds helper functions in JacksonUtils that enable reuse of
   SerializerProvider objects and updates various call sites to make
   use of this.

2) GroupByQueryToolChest copies the ObjectMapper for every query to
   install a special module that supports backwards compatibility with
   map-based rows. This isn't needed if resultAsArray is set and
   all servers are running Druid 0.16.0 or later. This release was a
   while ago. So, this patch disables backwards compatibility by default,
   which eliminates the need to copy the heavyweight ObjectMapper. The
   patch also introduces a configuration option that allows admins to
   explicitly enable backwards compatibility.
@lgtm-com
Copy link

lgtm-com bot commented Apr 21, 2022

This pull request introduces 1 alert when merging 9a40e35 into f954470 - view on LGTM.com

new alerts:

  • 1 for Dereferenced variable may be null

@FrankChen021
Copy link
Member

Should this be included in the upcoming 0.23?

* for each serialized object.
*/
public static void writeObjectUsingSerializerProvider(
final JsonGenerator jsonGenerator,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this helper API is used to replaceObjectMapper.writeValue and JsonGenerator.writeObject, can we prohibite these two methods in the druid-forbidden-apis.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea: I added them, and also updated the remaining call sites.

@lgtm-com
Copy link

lgtm-com bot commented Apr 22, 2022

This pull request introduces 1 alert when merging c8128ed into b762122 - view on LGTM.com

new alerts:

  • 1 for Dereferenced variable may be null

@gianm
Copy link
Contributor Author

gianm commented Apr 27, 2022

Should this be included in the upcoming 0.23?

IMO, it'd be OK to do it in 0.23, but it's not absolutely necessary.

@gianm gianm merged commit a2bad0b into apache:master Apr 27, 2022
@gianm gianm deleted the allocations-jackson branch April 27, 2022 21:17
@abhishekagarwal87 abhishekagarwal87 added this to the 24.0.0 milestone Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants