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

Add a way to configureSerializerCache Jackson uses #4111

Merged
merged 16 commits into from
Sep 23, 2023

Conversation

JooHyukKim
Copy link
Member

(Part of #2502)

Motification

Mostly similar to #4101 except SeriailzerCache constructor where I added a note for.

@JooHyukKim JooHyukKim changed the title Add a way to configure SerializerCache Jackson uses Add a way to configureSerializerCache Jackson uses Sep 11, 2023
@@ -71,7 +80,8 @@ private final synchronized ReadOnlyClassToSerializerMap _makeReadOnlyLookupMap()
// not correctness
ReadOnlyClassToSerializerMap m = _readOnlyMap.get();
if (m == null) {
m = ReadOnlyClassToSerializerMap.from(_sharedMap);
// TODO: Figure out how to pass something that can provides content-iterable without hard type casting.
m = ReadOnlyClassToSerializerMap.from((LRUMap<TypeKey, JsonSerializer<Object>>) _sharedMap);
Copy link
Member Author

Choose a reason for hiding this comment

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

This one needs more ideas. One option I can think of....

  • Add new method that returns Iterator<K,V> in LookupCache<K,V>. Possibly as a default method (for backward compatibility?)
  • Do some analysis and extract content() method from LRUMap or similiar type. Not sure on this one.

WDYT? /cc @cowtowncoder

EDITED : fixed bullet list format

Copy link
Member

Choose a reason for hiding this comment

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

This is tricky, yes. I wonder what does master (3.0) do here? I think it has/had similar problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I missed checking master 🥲 lemme go check real quick

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no difference in master branch 🧐

Copy link
Member Author

Choose a reason for hiding this comment

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

  • Add new method that returns Iterator<K,V> in LookupCache<K,V>. Possibly as a default method (for backward compatibility?)

Would adding an absract method

    Iterator<Map.Entry<K, V>> iterator();

...be breaking other modules? Seems reasonable

Copy link
Member

Choose a reason for hiding this comment

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

Well, master has this for LookupCache:

    // 17-Sep-2019, tatu: There is one usage, by `ReadOnlyClassToSerializerMap`, so
    //    for now NOT exposed, but can reconsider if it proves generally useful

//    void contents(BiConsumer<K,V> consumer);

so I think we could introduce such method, with default implementation of throwing UnsupportedOperationException.

The reason I prefer this is that it won't (have to) expose actual contents in a way that might allow modification.

@cowtowncoder
Copy link
Member

Merged #4114 so that should help -- thank you for pointing out the missing piece!

@JooHyukKim JooHyukKim marked this pull request as draft September 12, 2023 22:03
@JooHyukKim JooHyukKim marked this pull request as ready for review September 12, 2023 22:33
@JooHyukKim
Copy link
Member Author

JooHyukKim commented Sep 12, 2023

Retrofitted the change from #4114, and improved code level consistency with DeserializerCache ver. I think the PR can be reviewed again 👍🏼

}

@Test
public void testDefaultCacheProviderConfigSerializerCache() throws Exception
Copy link
Member

Choose a reason for hiding this comment

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

Not quite sure what is being tested here...

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests that with maxSerializerCacheSize set to positive value, works.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmmh. But it doesn't really check if it takes effect wrt changing cache size.
Just that nothing breaks in obvious way.

But I guess as sanity check, maybe extract common code that writes and reads output into helper method to reduce duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thankssss

}

@Test
public void testDefaultCacheProviderConfigSerializerCacheSizeZero() throws Exception
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, what exactly is being tested?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same here. Tests that with maxSerializerCacheSize set to zero, also works. Should we make test methods' names more meaningful or modify the tests themselves?

Copy link
Member

Choose a reason for hiding this comment

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

Minor refactoring to reduce duplicated code would be useful in that case.
Although also checking that cache being constructed specified size would be useful -- but wouldn't want to add methods just for test cases.

So yeah, reducing code duplication would be good, I'm ok with the tests otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe later we can consider adding accessors somewhere. I guess we can go with deduplication for now 🥲

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

@cowtowncoder
Copy link
Member

Getting close; I can hopefully merge this when I get back from my trip in 2 days.

@cowtowncoder cowtowncoder merged commit fa2024b into FasterXML:2.16 Sep 23, 2023
3 checks passed
@JooHyukKim JooHyukKim deleted the 2502-POC-forSerializerCache branch September 23, 2023 12:29
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