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

Tweak class caching in node (de)serializers. #1518

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

milesziemer
Copy link
Contributor

@milesziemer milesziemer commented Dec 1, 2022

Prior to this PR, class caching mechanisms in DefaultNodeDeserializers
and DefaultNodeSerializers would cache classes the first time they were
loaded. If the class was loaded again using a new ClassLoader, and then
retrieved from the cache, there would be a mismatch in the loaded class
and the one retrieved from the cache because class equality is dependent
on the ClassLoader used. This caused class cast exceptions in the language
server.

Based on discussion with Michael offline, this PR introduces a modified
caching mechanism that associates a key-value pair with an instance
of a loaded class. When retrieving a value from the cache, the associated
class is also provided, and the cache will be invalidated if the associated
class is not referentially equal to the currently cached class. This modified
caching mechanism replaces caches in DefaultNodeSerializers and
DefaultNodeDeserializers.

Testing

  • Test class for the new caching mechanism
  • Added test case to ModelAssemblerTest for loading external jars with trait
    implementations multiple times. The jar and model used for this test case
    was taken from the language server.
    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@milesziemer
Copy link
Contributor Author

Opening this as a draft because it still needs a test added, but I still have to think about how exactly to test with loading classes in.

@milesziemer
Copy link
Contributor Author

milesziemer commented Dec 2, 2022

Looking at this again and trying to update some of the comments, something started to seem not quite right. @mtdowling I was going off your suggestions, but either this implementation isn't exactly what we want, or it needs to be integrated into the node (de)serializers differently. See the diffs DefaultNodeDeserializers:626 and DefaultNodeSerializers:259: the class that is being cached, ObjectMapper and ClassInfo respectively, do not have the same class as the keys of the cache, Class and Class respectively. I added failing test case to show why this doesn't work.

Maybe we can use the previous implementation and this new one together, or we need to be able to use a different class as the key and value in IdentityClassCache.

Prior to this PR, class caching mechanisms in DefaultNodeDeserializers
and DefaultNodeSerializers would cache classes the first time they were
loaded. If the class was loaded again using a new ClassLoader, and then
retrieved from the cache, there would be a mismatch in the loaded class
and the one retrieved from the cache because class equality is dependent
on the ClassLoader used. This caused class cast exceptions in the language
server.

Based on discussion with Michael offline, this PR introduces a modified
caching mechanism that associates a key-value pair with an instance
of a loaded class. When retrieving a value from the cache, the associated
class is also provided, and the cache will be invalidated if the associated
class is not referentially equal to the currently cached class. This modified
caching mechanism replaces caches in DefaultNodeSerializers and
DefaultNodeDeserializers.

Testing
------
- Test class for the new caching mechanism
- Added test case to ModelAssemblerTest for loading external jars with trait
implementations multiple times. The jar and model used for this test case
was taken from the language server.
@milesziemer milesziemer marked this pull request as ready for review December 7, 2022 17:29
@milesziemer milesziemer requested a review from a team as a code owner December 7, 2022 17:29
@kubukoz
Copy link
Contributor

kubukoz commented Dec 12, 2022

Hey @milesziemer, can you share an estimate of when this might be released? It'd be much appreciated, thanks!

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.

6 participants