Skip to content

Improve mapping manager synchronization#803

Merged
adutra merged 2 commits into
apache:3.xfrom
avivcarmis:3.x
Feb 16, 2017
Merged

Improve mapping manager synchronization#803
adutra merged 2 commits into
apache:3.xfrom
avivcarmis:3.x

Conversation

@avivcarmis
Copy link
Copy Markdown

following discussion on previous PR.

Copy link
Copy Markdown
Contributor

@adutra adutra left a comment

Choose a reason for hiding this comment

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

👍

@adutra adutra changed the title Improve mapping manager synchronization on top of 3.x Improve mapping manager synchronization Feb 13, 2017
@adutra adutra added this to the 3.2.0 milestone Feb 13, 2017
Copy link
Copy Markdown
Contributor

@tolbertam tolbertam left a comment

Choose a reason for hiding this comment

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

looks great to me, just a note to make sure when merging to get rid of the 4ca1737 commit which just looks like a trivial no-change merge commit.

mapper = new Mapper<T>(this, klass, entityMapper);
Mapper<T> old = (Mapper<T>) mappers.putIfAbsent(klass, mapper);
if (old != null) {
mapper = old;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🐼 my bad, I was looking at the diff view on github and I only focused on the changed lines.

@adutra adutra merged commit f0948b0 into apache:3.x Feb 16, 2017
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.

4 participants