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

Fix for #180 #184

Merged
merged 2 commits into from
Apr 20, 2014
Merged

Fix for #180 #184

merged 2 commits into from
Apr 20, 2014

Conversation

romix
Copy link
Collaborator

@romix romix commented Jan 25, 2014

Hi, please find for your review the initial support for field annotations (#180). It is fully functional and I provided unit tests for it as part of FieldSerializerTest.

Any comments are welcome!

@pheer
Copy link

pheer commented Jan 27, 2014

Cool, thanks a ton! Since we have to annotate every domain object in our app will this potentially get expensive in creating serializer objects? Does the following make sense to add for potential performance improvement:

            // here we capture a specific serializer for a particular field
            if (field.isAnnotationPresent(BindKryoSerializer.class)) {
                Class<? extends Serializer> serializerClass = field.getAnnotation(BindKryoSerializer.class).value();
                Serializer setSerializer = super.getKryo().getSerializer(field.getClass());

                if (serializerClass.isInstance(setSerializer)) {
                    fields[i].setSerializer(setSerializer);
                } else {
                    Serializer s = ReflectionSerializerFactory.makeSerializer(super.getKryo(), serializerClass,
                            field.getClass());
                    fields[i].setSerializer(s);
                }
            }

Basically it doesn't use the reflection factory to create the serializer if it is already that serializer. Not sure if this makes sense in the grand scheme of things. Thanks again!

@romix
Copy link
Collaborator Author

romix commented Jan 28, 2014

@pheer Thanks for your comment. Your idea of checking for known serializers is good. But I'm not sure that the way how you perform this check and reuse it is correct. Basically, it reuses the same instance of a serializer. And this is not allowed in most cases. Instead, one should probably ask Kryo to create a new instance of a serializer for a registered class. It can still be cheaper or at most as expensive as using a reflection factory.

Another possible optimization: We can cache serializer classes seen so far.

@pheer
Copy link

pheer commented Jan 28, 2014

Okay, that makes sense. Thanks!

static public class MultipleTimesAnnotatedCollectionFields {
// This annotation should result in an exception, because
// it is applied to a non-collection field
@CollectionSerializer.BindKryoSerializer(
Copy link
Member

Choose a reason for hiding this comment

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

Seems a bit verbose. Maybe just "CollectionSerializer.Bind("?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that is a bit verbose. I renamed it into "Bind" now. But I see one small issue: If someone uses CollectionSerializer.Bind, MapSerializer.Bind and FieldSerializer.Bind in the same file then only one of them can be used without a class name prefix (i.e. without XXXSerializer) and all others have to use it, because the name of the annotation is the same. Is it bad? May be we should have BindCollection, BindMap and Bind as names instead? Then users may use these shortcuts without class names in front of them.

@NathanSweet
Copy link
Member

Seems ok to me. We seem to loop through all the fields in FieldSerializer multiple times. FieldSerializer in general has become a scary monster for me, I hardly recognize it. I wonder if it can be refactored to separate logic into individual components.

@romix
Copy link
Collaborator Author

romix commented Apr 4, 2014

@pheer: Regarding the optimization of serializer instances creation: There are some possibilities, but they would make the code more complex. So I'm wondering if it is a premature optimization? After all, serializers are created only once, when a FieldSerializer is constructed. During serialization/deserialization no new serializer instances are created. Have you really detected that this code becomes a bottleneck in your application?

@pheer
Copy link

pheer commented Apr 4, 2014

@romix: no I just noticed it. I agree this may be a premature
optimization.

On Fri, Apr 4, 2014 at 8:29 AM, romix [email protected] wrote:

@pheer https:/pheer: Regarding the optimization of
serializer instances creation: There are some possibilities, but they would
make the code more complex. So I'm wondering if it is a premature
optimization? After all, serializers are created only once, when a
FieldSerializer is constructed. During serialization/deserialization no new
serializer instances are created. Have you really detected that this code
becomes a bottleneck in your application?

Reply to this email directly or view it on GitHubhttps://pull/184#issuecomment-39577663
.

@romix
Copy link
Collaborator Author

romix commented Apr 4, 2014

@pheer OK. Thanks for your reply.

BTW, what do you think about the issue with naming of annotations I mentioned above? I mean this: #184 (comment)

@romix
Copy link
Collaborator Author

romix commented Apr 8, 2014

@NathanSweet @pheer Ping! If possible, I'd like to hear your opinion about annotation names before I provide a final version PR.

@romix
Copy link
Collaborator Author

romix commented Apr 17, 2014

Ping!

@pheer
Copy link

pheer commented Apr 18, 2014

Sorry I was out of network range for a while (needed to get away from
computers for a while :-)). I don't really mind names being verbose. Just
means we know excatly what it is then. Although BindKryoSerializer is
probably not the best choice. +1 on what you suggested. BindMap,
BindCollection. I haven't checked this out in detail yet. Thanks again

On Thu, Apr 17, 2014 at 8:17 AM, romix [email protected] wrote:

Ping!


Reply to this email directly or view it on GitHubhttps://pull/184#issuecomment-40725559
.

@romix romix merged commit c8b6367 into EsotericSoftware:master Apr 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants