-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve][misc] Use shared Jackson ObjectMapper to reduce overhead and remove ThreadLocal solution #19160
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
[improve][misc] Use shared Jackson ObjectMapper to reduce overhead and remove ThreadLocal solution #19160
Conversation
c8ef4d8 to
05ef22c
Compare
05ef22c to
10772b8
Compare
Codecov Report
@@ Coverage Diff @@
## master #19160 +/- ##
============================================
- Coverage 47.89% 47.36% -0.53%
+ Complexity 10871 10729 -142
============================================
Files 713 713
Lines 69730 69723 -7
Branches 7496 7497 +1
============================================
- Hits 33394 33024 -370
- Misses 32631 32974 +343
- Partials 3705 3725 +20
Flags with carried forward coverage won't be shown. Click here to find out more.
|
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonWriter.java
Show resolved
Hide resolved
- ObjectMapper is thread safe
|
@nicoloboschi PTAL . I have added a ProtectedObjectMapper class which prevents mutating the shared ObjectMapper config. |
nicoloboschi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I like the new pattern 👍
| Optional<Long> version) { | ||
| try { | ||
| byte[] content = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies); | ||
| byte[] content = ObjectMapperFactory.getMapper().writer().writeValueAsBytes(policies); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about having ObjectMapperFactory.getWriter() and ObjectMapperFactory.getReader() methods ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of that, but the challenge is that there's also the Yaml versions and the ObjectMapper configured to filter null fields. That would result in a lot of similar methods. It's a tradeoff.
Leaving ObjectMapperFactory as-is and creating a completely new class would be another option. I'd suggest that it's left as another PR to continue refactoring.
…sses - prevents classloader & class leaks
…s to empty caches - this is useful in tests to prevent class / classloader leakages
Motivation
Creating a Jackson ObjectMapper is an expensive operation. A thread local ObjectMapper instance is already used in most locations.
Additional motivation is to be able to use a properly configured ObjectMapper instance with Jackson Java 8 modules. That PR is #19161 .
Modifications
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: lhotari#124