Skip to content

Commit

Permalink
Improve performance of CB GetFirstPassWriter
Browse files Browse the repository at this point in the history
Some performance testing showed a regression in Compact Binary v1
performance after support for v2 was added. The biggest contributor to
the regression was boxing being done in
CompactBinaryWriter.GetFirstPassWriter.

The previous implementation of CompactBinaryWriter.GetFirstPassWriter,
when v1 was being used, was boxing a null to a
Nullable<CompactBinaryCounter> and then converting that to a null
IProtocolWriter.

With this change, the version 1 code path just returns a null
IProtocolWriter, avoiding the expensive box. The performance difference
on the test I was using is now negligible.
  • Loading branch information
chwarr committed Apr 28, 2016
1 parent 64d38e7 commit c8aa255
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cs/src/core/protocols/CompactBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ public CompactBinaryWriter(O output, ushort version = 1)

public IProtocolWriter GetFirstPassWriter()
{
return version == 2 ? firstPassWriter : null;
if (version == 2)
{
return firstPassWriter.Value;
}

return null;
}

/// <summary>
Expand Down

0 comments on commit c8aa255

Please sign in to comment.