Skip to content

Reduce string allocations in XmlWriterTraceListener - #66762

Merged
danmoseley merged 1 commit into
dotnet:mainfrom
stephentoub:xmltracealloc
Mar 18, 2022
Merged

Reduce string allocations in XmlWriterTraceListener#66762
danmoseley merged 1 commit into
dotnet:mainfrom
stephentoub:xmltracealloc

Conversation

@stephentoub

Copy link
Copy Markdown
Member

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

usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;usingSystem.Diagnostics;usingSystem.IO;[MemoryDiagnoser]publicclassProgram{staticvoidMain(string[]args)=>BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);privateXmlWriterTraceListener_listener=newXmlWriterTraceListener(Stream.Null);privateTraceEventCache_cache=newTraceEventCache();[Benchmark]publicvoidTrace(){_listener.TraceEvent(_cache,"something",TraceEventType.Information,42);}}
MethodToolchainMeanErrorRatioAllocated
Trace\main\corerun.exe585.9 ns9.29 ns1.00272 B
Trace\pr\corerun.exe481.7 ns3.88 ns0.8224 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
Copy Markdown

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.

usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;usingSystem.Diagnostics;usingSystem.IO;[MemoryDiagnoser]publicclassProgram{staticvoidMain(string[]args)=>BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);privateXmlWriterTraceListener_listener=newXmlWriterTraceListener(Stream.Null);privateTraceEventCache_cache=newTraceEventCache();[Benchmark]publicvoidTrace(){_listener.TraceEvent(_cache,"something",TraceEventType.Information,42);}}
MethodToolchainMeanErrorRatioAllocated
Trace\main\corerun.exe585.9 ns9.29 ns1.00272 B
Trace\pr\corerun.exe481.7 ns3.88 ns0.8224 B
Author:stephentoub
Assignees:stephentoub
Labels:

area-System.Xml

Milestone:-

@danmoseley
danmoseley merged commit bfa629e into dotnet:mainMar 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.
@ghostghost 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 freeto 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

@stephentoub@danmoseley@marek-safar