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

Performance #92

Closed
rogeralsing opened this issue Aug 14, 2015 · 10 comments
Closed

Performance #92

rogeralsing opened this issue Aug 14, 2015 · 10 comments

Comments

@rogeralsing
Copy link

Hi,
I have been comparing the perf of Migrant with Json.NET today and the results were a bit on the weak side.
It turned out that Migrant is about 24 times slower than Json.NET.
I do get that there is more data to handle with Migrant as it includes a lot more in the payload than json.net does.

Here is a is a screenshot of a profiling session:

migrantperf

And here is the (extremely naive) perf test I used https://gist.github.com/rogeralsing/7b57167935ce048859e7
The test is designed to simulate what we do in Akka.NET, thus the byte array stuff in there.

According to the profiling session, it does look like there is a specific method that is responsible for most of the cpu consumption, TouchAndWriteAssemblyId

Are there any settings that can omit some of the expensive information from the payload or are the default settings the fastest?

@rogeralsing
Copy link
Author

In ObjectWriter.cs - TouchAndWriteAssemblyId

if(assemblyIndices.ContainsKey(assembly))
            {
                assemblyId = assemblyIndices[assembly];

Changing that into a assemblyIndices.TryGetValue would make it twice as fast as there is just one hash lookup instead of two (first checking existence and then getting the value)

[Edit]
I just tried that, total time for 100 000 objects went from 4.5 sec to 2.9 sec. so definitely an improvement.

@rogeralsing
Copy link
Author

I've got the total time down to 0.898 sec now. it turns out that the Equality comparison for AssemblyDescriptor uses string join and some linq to generate the FullName of the assembly, the full name is then used in the equality comparison.
So just by caching the FullName of the assembly descriptor made things a ton better.

@konrad-kruczynski
Copy link
Contributor

Hi roger,
first of all the way Migrant is used in the test is not the one Migrant is meant to be used, since with each new serialize it has to create all type stamps and headers. Please compare serializing 100000 objects in a loop to 100000 objects contained in an array and serialized using one Serialize call. Then, depending on the scenario you have, you either want to use open stream serialization or some collection.

@konrad-kruczynski
Copy link
Contributor

Normally the heavy process you're mainly profiling now is done only once per type (so in case of 100000 instances the time it takes in negligible).

@konrad-kruczynski
Copy link
Contributor

Nonetheless your findings are still interesting and will be analyzed (you can even post a pull request if you'd like to).

@konrad-kruczynski
Copy link
Contributor

I've modified your test snippet according to what I've written above. Look at it here: https://gist.github.com/konrad-kruczynski/2636b9c2eaa37961c38b

Please run it and tell me whether it suits your needs. Note that the open stream mode is not yet as optimized as the "all the stuff in one call" one, but can be tweaked.

@konrad-kruczynski
Copy link
Contributor

I've used your TryGetValue tip in ObjectIdentifier.

@konrad-kruczynski
Copy link
Contributor

By temporary removing stamping (just as an experiment now, not the final version) I was able to get down from 4.1s to 0.45s on my PC (your unmodified tests). So it will definitely be a way to go.

@mateusz-holenko
Copy link
Member

I created a separate issue on creating an option to disable type stamping: #98.

@konrad-kruczynski
Copy link
Contributor

I am closing this ticket for now since its problems are analyzed in #93 and #98.

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

No branches or pull requests

3 participants