Skip to content

Conversation

@stephentoub
Copy link
Member

Rather than ToString'ing everything, most of the header data can be formatted into a span and then written out to the writer.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Diagnostics;
using System.IO;

[MemoryDiagnoser]
public class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

    private XmlWriterTraceListener _listener = new XmlWriterTraceListener(Stream.Null);
    private TraceEventCache _cache = new TraceEventCache();

    [Benchmark]
    public void Trace()
    {
        _listener.TraceEvent(_cache, "something", TraceEventType.Information, 42);
    }
}
Method Toolchain Mean Error Ratio Allocated
Trace \main\corerun.exe 585.9 ns 9.29 ns 1.00 272 B
Trace \pr\corerun.exe 481.7 ns 3.88 ns 0.82 24 B

Rather than ToString'ing everything, most of the header data can be formatted into a span and then written out to the writer.
@ghost
Copy link

ghost commented Mar 18, 2022

Tagging subscribers to this area: @dotnet/area-system-xml
See info in area-owners.md if you want to be subscribed.

Issue Details

Rather than ToString'ing everything, most of the header data can be formatted into a span and then written out to the writer.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Diagnostics;
using System.IO;

[MemoryDiagnoser]
public class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

    private XmlWriterTraceListener _listener = new XmlWriterTraceListener(Stream.Null);
    private TraceEventCache _cache = new TraceEventCache();

    [Benchmark]
    public void Trace()
    {
        _listener.TraceEvent(_cache, "something", TraceEventType.Information, 42);
    }
}
Method Toolchain Mean Error Ratio Allocated
Trace \main\corerun.exe 585.9 ns 9.29 ns 1.00 272 B
Trace \pr\corerun.exe 481.7 ns 3.88 ns 0.82 24 B
Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Xml

Milestone: -

@danmoseley danmoseley merged commit bfa629e into dotnet:main Mar 18, 2022
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
Rather than ToString'ing everything, most of the header data can be formatted into a span and then written out to the writer.
@ghost ghost locked as resolved and limited conversation to collaborators Apr 17, 2022
@stephentoub stephentoub deleted the xmltracealloc branch May 18, 2022 20:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants