Improve mapping manager synchronization#803
Merged
Merged
Conversation
olim7t
suggested changes
Feb 15, 2017
| mapper = new Mapper<T>(this, klass, entityMapper); | ||
| Mapper<T> old = (Mapper<T>) mappers.putIfAbsent(klass, mapper); | ||
| if (old != null) { | ||
| mapper = old; |
Contributor
There was a problem hiding this comment.
This is not exactly the same as the previous version, now we create a new instance each time, even if the entry existed in the map.
For getMapper and getAccessor it doesn't matter that much, because they're only called directly by the client (and in general they will probably only do it once), but getUDTCodec is also called internally, each time a new class with an UDT field is parsed.
Checking the map first is simple enough, so I think we should do it in all cases:
Mapper<T> old = (Mapper<T>) mappers.get(klass);
if (old != null) {
return old;
}
EntityMapper<T> entityMapper = AnnotationParser.parseEntity(klass, this);
mapper = new Mapper<T>(this, klass, entityMapper);
old = (Mapper<T>) mappers.putIfAbsent(klass, mapper);
if (old != null) {
mapper = old;
}
return mapper;
It can still create an unnecessary instance, but the window is much shorter.
Contributor
There was a problem hiding this comment.
🐼 my bad, I was looking at the diff view on github and I only focused on the changed lines.
olim7t
approved these changes
Feb 16, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
following discussion on previous PR.