Skip to content

Conversation

@samcragg
Copy link
Contributor

@samcragg samcragg commented Jul 9, 2016

We were optimizing the memory usage during start up of our application and noticed there were lots of string allocations when creating the serializers.

I profiled the BasicUsage sample in Visual Studio and 7,211,352 total bytes were allocated in 1.9 seconds (slow because the profiler was attached). After the changes in this changeset these figures changed to 1,164,024 total bytes allocated and it finished in 1.1 seconds (again, this is slower than normal because the profiler was attached), so quicker and using a lot less memory during the creation of the serializers (less pressure on the GC, which was what we were investigating in our app in general so thought I'd pass the savings on to others ).

The cause is because the TextWriter.Null property returns an internal NullTextWriter class that only overloads the Write(string) method, meaning that anytime you call TextWriter.Null.Write("format", object) there's a call to string.Format which then gets thrown away. All I've done is generated a class that implements TextWriter and overrides all the methods it can and does nothing in them.

I've only modified the MsgPack.sln solution - there looks like there's an automated process for syncing the changes to the other solutions?

Implemented a TextWriter that doesn't call string format on the
arguments to prevent redundant work that will not be outputted.
@yfakariya yfakariya merged commit b05b7a1 into msgpack:master Jul 9, 2016
yfakariya added a commit that referenced this pull request Jul 9, 2016
This commit includes:
* Synchronize projects.
* Add conditionals for Silverlight, UWP, and .NET Standards.
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.

2 participants