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

Provide an opt-out for disabling the optimization of generics serialization #433

Merged
merged 1 commit into from Jun 25, 2016

Conversation

romix
Copy link
Collaborator

@romix romix commented Jun 11, 2016

The existing optimization of generics serialization aims at reducing the size of the serialized representation. This optimization is enabled by default. But sometimes it may have a negative impact on performance. And sometimes it cannot handle complex cases of generics usage.

This patch changes the default behavior and disables this this optimization. To enable it, simply invoke FieldSerializerConfig.setOptimizedGenerics(true).

@romix romix changed the title Provide an opt-out for disabling the optimization of generics seriali… Provide an opt-out for disabling the optimization of generics serialization Jun 11, 2016
@magro
Copy link
Collaborator

magro commented Jun 12, 2016

AFAICS the following issues might benefit from this PR and should be checked with the changes of this PR: #377, #384 (#385), #411

Updates:

CachedField cachedField;

if (fieldGenericType == fieldClass[0]) {
if (!config.isOptimizedGenerics() || fieldGenericType == fieldClass[0]) {
// This is a field without generic type parameters
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment should probably be changed now.

@romix
Copy link
Collaborator Author

romix commented Jun 12, 2016

@magro I'm not sure about the interplay of the config field of the FieldSerializer and my patch. If someone would change the optimizedGenerics setting of the config from true to false after a FieldSerializer was build using this config, then it could lead to undefined behavior.

May be FieldSerializer should get a non-modifiable copy of the config?

);
kryo.getFieldSerializerConfig().setOptimizedGenerics(false);
runTests(
"standard-nonopt-generics",
Copy link
Collaborator

@magro magro Jun 12, 2016

Choose a reason for hiding this comment

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

The new files (test/resources/*-standard-nonopt-generics.ser) created when running this SerializationCompatTest should be added to git (applies to other new nonopt files as well).

@magro
Copy link
Collaborator

magro commented Jun 12, 2016

@romix Thanks again for your work here! Can you elaborate a bit more on the consequences of the optimizedGenerics setting being true or false (e.g. with some examples and size/time measurements)? If you don't have the time for this I could also help with building a simple benchmark.
Update: we should also mention this setting in the README/FieldSerializer section.

As I understand it, with non-optimized generics we should have faster (de)serialization of generics but increased size, and generics serialization should be more robust. Assuming that generics serialization is in-fact more robust with this setting, I wonder if we should make this the default (if we'd release this then as 4.0 or 3.1 is a different question). WDYT?

/cc @NathanSweet

@magro
Copy link
Collaborator

magro commented Jun 12, 2016

@romix The FieldSerializer could also "freeze" this setting in the cloned
config by setting a special flag, so that the setter throws a exception if
called on the clone.

romix notifications@github.com schrieb am Mo., 13. Juni 2016, 00:18:

@magro https://github.com/magro I'm not sure about the interplay of the
config field of the FieldSerializer and my patch. If someone would change
the optimizedGenerics setting of the config from true to false after a
FieldSerializer was build using this config, then it could lead to
undefined behavior.

May be FieldSerializer should get a non-modifiable copy of the config?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#433 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAD7HbmVdZxuTv3e2gDBOLyPnTWmkoDfks5qLIWrgaJpZM4IzpmB
.

@romix
Copy link
Collaborator Author

romix commented Jun 13, 2016

@magro Regarding the consequences of this patch on size/performance: I haven't written or executed any benchmarks due to the lack of time. But your understanding is correct. I expect exactly the same as you do: with non-optimized generics we should have faster (de)serialization of generics but increased size, and generics serialization should be more robust. Basically, the size is likely the be roughly the same as it used to be before I introduced those generics optimizations a while ago.

It would be nice if you or someone else could help with the benchmarking of this non-optimized mode.

As for making it a default, I'm not sure. But it could be a good idea, indeed. Though, it would be a breaking change, because it changes the default binary serialization format in case of generics. People willing to proceed with the existing format will have to change their source code and enable the setting by hand.

@magro
Copy link
Collaborator

magro commented Jun 17, 2016

@romix Sorry for the late response, this week was very busy.

I'm going to submit a PR with my comments / proposed changes against your branch. If you're already working on it please ping me now so that we don't do double work.

Not sure if I'll have time for the benchmark as well, perhaps I'll submit a separate PR later against master.

Making the non-optimized mode the default: this is my preference, as it should improve stability and reduce submitted issues. I'll ask on the mailing list for opinions, let's see if there's feedback.

@magro
Copy link
Collaborator

magro commented Jun 17, 2016

@romix I just submitted my feedback as PR. If you think all this is fine you could merge + rebase/squash commits to a single one - and IMO we could merge it then. The most critical thing is that change for the optimizedGenerics default value :-)

@romix
Copy link
Collaborator Author

romix commented Jun 18, 2016

@magro Thanks a lot for your PR!

@romix
Copy link
Collaborator Author

romix commented Jun 22, 2016

@magro I force-pushed the new version of the patch. It includes all of your changes and my changes to avoid any hacks related to freezing of the FieldSerializerConfig.setOptimizedGenerics.

Please check if everything is OK and we could merge this.

@magro
Copy link
Collaborator

magro commented Jun 25, 2016

@romix Sorry for the late response... Because optimization is off by default the commit message is wrong in this regard. Can you update it? The readme probably should also mention this setting, but I could write that later as well.

… for enabling/disabling it.

The existing optimization of generics serialization aims at reducing the size of the serialized representation. This optimization is enabled by default. But sometimes it may have a negative impact on performance. And sometimes it cannot handle complex cases of generics usage.

This patch changes the default behavior and disables this this optimization. To enable it, simply invoke `FieldSerializerConfig.setOptimizedGenerics(true)`.
@romix
Copy link
Collaborator Author

romix commented Jun 25, 2016

@magro Good catch! I updated the commit message. The readme could be updated later, when we roll out a new release.

@magro
Copy link
Collaborator

magro commented Jun 25, 2016

So it's done now, great work!!

@romix
Copy link
Collaborator Author

romix commented Jul 1, 2016

@magro Martin, I'm not sure that closing all those related issues is the right thing to do. I agree that with #433 they are not present in the non-generic-optimized mode. But they are still present when generic optimizations are enabled. Therefore, I'd suggest tagging them with "optimize-generics" or something like this, instead of closing. WDYT?

@magro
Copy link
Collaborator

magro commented Jul 2, 2016

@romix Sounds good!

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.

None yet

2 participants