Skip to content

Instantiators for additional container classes #4300

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

Merged
merged 10 commits into from
Jan 20, 2024

Conversation

edudar
Copy link
Contributor

@edudar edudar commented Jan 3, 2024

Took a stab at #4299

Added support for LinkedList, HashSet, TreeSet, ConcurrentHashMap, and TreeMap.

Also, replaced other new instantiator invocations with singletons.

edudar added 2 commits January 3, 2024 00:41
…hSet, TreeSet, ConcurrentHashMap, and TreeMap. Replaced other new instantiator invocations with singletons.
@edudar edudar requested a review from JooHyukKim January 3, 2024 18:15
Copy link
Member

@JooHyukKim JooHyukKim left a comment

Choose a reason for hiding this comment

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

👍🏼

if (Collections.EMPTY_SET.getClass() == raw) {
return new ConstantValueInstantiator(Collections.EMPTY_SET);
return ConstantValueInstantiator.EMPTY_SET_INSTANCE;
Copy link
Member

Choose a reason for hiding this comment

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

No, I think these should not be pre-created since they are relatively rarely needed.
Let's leave them dynamically created on as-needed basis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are they cached somewhere, or will they be instantiated for each deserialization call? I looked around, and it looked like the latter, which is why I made them all like that. If they are cached then it'd make sense to create them as we go and let cache handle the rest.

Copy link
Member

@cowtowncoder cowtowncoder Jan 4, 2024

Choose a reason for hiding this comment

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

They are actually cached as part of JsonDeserializer created, but not separately. End result should be the same tho.

I think eager creation is fine for default fallback types (ArrayList, LinkedHashMap, HashSet?).
Fine to also use for JsonLocation. These are more speculative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I gave it another spin. Default fallbacks remained eager, the rest moved to lazy. Seems like a sweet spot between eager and new.

Copy link
Member

Choose a reason for hiding this comment

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

Ah. I should have been more careful here; by lazily I just meant creating instance directly with new -- effective caching is, as I said, indirect: actual JsonDeserializer created for specific type will use ValueInstantiator.

But I can actually make changes before merging so I think this is fine.
(also, due to the way class loaders work, I think final static instance fields are actually only constructed when class is initialized which does not occur -- AFAIK -- before "substantial" access (or whatever term was used), and not simply because class is referenced).

All I need now is the CLA, as per my note further down. Once that is done I can do whatever mas

@cowtowncoder
Copy link
Member

@edudar Looks good overall, thank you for submitting this.

One question tho: is the eager construction required to let GraalVM compiler find and included needed references?
If so that makes sense.
Otherwise I'd prefer lazy construction for types that are NOT default mappings.

Second practical thing: before merging the pr we'd need CLA (unless you have sent one before). It's from here:

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

and easiest to print, fill & sign, scan/photo, email to cla at fasterxml dot com.
This only needs to be done once before the first contribution and is good for any future pull requests.

@cowtowncoder cowtowncoder added the cla-needed PR looks good (although may also require code review), but CLA needed from submitter label Jan 14, 2024
cowtowncoder added a commit that referenced this pull request Jan 16, 2024
@cowtowncoder
Copy link
Member

@edudar Ok, I went ahead and made changes I think would make sense, wrt. only pre-creating/lazily-reusing instantiators for default mapped types. Please let me know if you have concerns.

At this point I am ready to merge changes, but would need CLA that I mentioned above.

It would also be good if you could test changed version against GraalVM image, just to make sure I didn't break anything there.

Looking forward to merging this PR!

@cowtowncoder cowtowncoder removed the cla-needed PR looks good (although may also require code review), but CLA needed from submitter label Jan 20, 2024
@cowtowncoder
Copy link
Member

CLA received, hoping to merge soon.

@cowtowncoder cowtowncoder added the 2.17 Issues planned at earliest for 2.17 label Jan 20, 2024
@cowtowncoder cowtowncoder merged commit 66d39f4 into FasterXML:2.17 Jan 20, 2024
@edudar edudar deleted the extra-jdk-value-instantiators branch January 21, 2024 19:33
@cowtowncoder cowtowncoder added this to the 2.17.0 milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.17 Issues planned at earliest for 2.17
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants