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

Custom JsonGenerator with optimized writeObject() for simple object types #728

Merged
merged 2 commits into from
Jan 5, 2022

Conversation

brenuart
Copy link
Collaborator

Wrap the JsonGenerator with an optimized version of the writeObject() method that tries to call the appropriate write() method for the giveb untype Object and delegate to the underlying JsonGenerator as fallback.

Without this optimisation the writeObject() delegates to the underlying Codec which is less effective for simple types (String, Numbers, Boolean, byte[], JsonNode, etc) both in terms of CPU and temporary memory allocations.

Until now only the AbstractJsonPatternParser was using this optimisation. This commit moves it directly inside the JsonGenerator so it can benefit to any JsonProvider.

…ypes

Wrap the JsonGenerator with an optimized version of the writeObject() method that tries to call the appropriate write() method for the giveb untype Object and delegate to the underlying JsonGenerator as fallback.

Without this optimisation the writeObject() delegates to the underlying Codec which is less effective for simple types (String, Numbers, Boolean, byte[], JsonNode, etc) both in terms of CPU and temporary memory allocations.

Until now only the AbstractJsonPatternParser was using this optimisation. This commit moves it directly inside the JsonGenerator so it can benefit to any JsonProvider.
@brenuart brenuart added this to the 7.1 milestone Dec 28, 2021
@codecov
Copy link

codecov bot commented Dec 28, 2021

Codecov Report

Merging #728 (151a11e) into main (3802169) will increase coverage by 1.01%.
The diff coverage is 95.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #728      +/-   ##
============================================
+ Coverage     69.44%   70.45%   +1.01%     
- Complexity     1206     1223      +17     
============================================
  Files           161      162       +1     
  Lines          4719     4719              
  Branches        481      481              
============================================
+ Hits           3277     3325      +48     
+ Misses         1189     1147      -42     
+ Partials        253      247       -6     
Impacted Files Coverage Δ
...t/logstash/logback/composite/JsonWritingUtils.java 69.44% <ø> (+18.31%) ⬆️
...ogback/util/SimpleObjectJsonGeneratorDelegate.java 94.84% <94.84%> (ø)
...back/composite/AbstractCompositeJsonFormatter.java 79.61% <100.00%> (ø)
...ash/logback/pattern/AbstractJsonPatternParser.java 91.25% <100.00%> (ø)
...ck/appender/AbstractLogstashTcpSocketAppender.java 69.23% <0.00%> (-0.52%) ⬇️
...h/logback/composite/FastISOTimestampFormatter.java 98.80% <0.00%> (+1.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3802169...151a11e. Read the comment docs.

@brenuart brenuart merged commit 7201ea6 into main Jan 5, 2022
@brenuart brenuart deleted the simpleobjectjsongenerator branch January 5, 2022 12:20
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

Successfully merging this pull request may close these issues.

None yet

2 participants