Using ObjectReader to cache Jackson bindings when parsing JWT #194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey Guys,
While perf testing a web service which uses auth0-spring-security-api, I noticed that a chunk of performance was getting taken up by Jackson's ObjectMapper.readValue due to the reflection required on every call to set up its bindings.
Thankfully, Jackson provides an ObjectReader which caches the bindings for us, and is completely thread safe once after initial configuration. Since all configuration happens in the JWTParser header, this is perfectly safe to do and provides some significant performance improvements.
Here is a quick and dirty test I wrote to test the performance:
This gives the following using this version of the code on my Core i5 2.5GHz x4 16GB:
Running only the static tests on master gives the following:
which equates to a rather nice performance improvement on a web server under load.
Would someone consider merging this in and releasing a new version so I can make another PR on auth0-spring-security-api? I'm happy to make an alternative implementation if you're not happy with this one.