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

Cache formatter with offset parsed #120

Merged

Conversation

guidomedina
Copy link

@guidomedina guidomedina commented Dec 18, 2020

Cache formatter with offset parsed which can create lots of allocation when de-serialising Json objects with many date/time when the time/zone is preserved.

We have observed this is big GC hotspot, the solution is simple; to cache it, when no locale is used and the feature DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE is disabled a new formatter is always instantiated.

@@ -59,6 +62,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base,
{
super(base, useTimestamp);
_formatter = base._formatter;
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
Copy link
Member

Choose a reason for hiding this comment

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

This probably could just be base._formatterWithOffsetParsed?

Copy link
Author

@guidomedina guidomedina Dec 19, 2020

Choose a reason for hiding this comment

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

The reason for this vanilla copy & paste is just in case _formatter is changed to something else in the future, so that you don't have to also maintain the value at _formatterWithOffsetParsed

The idea is, whatever is assigned to _formatter, create a with offset parsed version of exactly that.
Do let me know if the reason I stated justifies it, if you still don't agree I will change it to what you have suggested.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have strong feelings here -- seems like avoiding another operation would be nice, but then again this is not in the hot codepath (as (de)serializer that uses it is cached). So I'll trust your judgment with it.

@@ -104,6 +111,7 @@ protected JacksonJodaDateFormat(JacksonJodaDateFormat base,
{
super(base);
_formatter = base._formatter;
_formatterWithOffsetParsed = _formatter.withOffsetParsed();
Copy link
Member

Choose a reason for hiding this comment

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

Can also just copy?

Copy link
Author

Choose a reason for hiding this comment

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

Same reason as my previous comment.

@cowtowncoder
Copy link
Member

Sounds good, thank you for PR!

One small request: could you rebase this against either 2.11 or 2.12? master is for Jackson 3.0 which won't be released very soon but 2.12.1 patch should be out in a couple of weeks (and 2.11.5 eventually too).

@guidomedina guidomedina force-pushed the cache-formatter-with-offset-parsed branch from 4d94a11 to 5f89426 Compare December 19, 2020 11:00
@guidomedina guidomedina changed the base branch from master to 2.12 December 19, 2020 11:01
@guidomedina
Copy link
Author

guidomedina commented Dec 19, 2020

I have rebased and change the base to origin/2.12

@cowtowncoder cowtowncoder merged commit 6f8bfd5 into FasterXML:2.12 Dec 20, 2020
@cowtowncoder
Copy link
Member

Looks good, happy to merge.

Just one thing: I am not 100% sure if I had asked for this before, but if not, a CLA would be needed before the first contribution (but just once so if you did send one at an earlier point that'd be fine -- same in future for other contributions). Document is here:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

and the usual way is to print it, fill & sign, scan/photo, email to info at fasterxml dot com.

Looking forward to merging this in 2.12, thank you for the contribution!

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.

2 participants