xoofx / SharpYaml

SharpYaml is a .NET library for YAML compatible with CoreCLR
Other
334 stars 61 forks source link

Use StringLookaheadBuffer if a string is available. #87

Closed maxvoxel8 closed 3 years ago

maxvoxel8 commented 3 years ago

Performance improvement to use StringLookaheadBuffer where a string can be directly accessed. This proves important especially with YAML that has a lot of quoted values that makes heavy use of ScanFlowScalar.

This is a before and after comparison in DotTrace using Sample mode: image

This is using Tracing mode: image

maxvoxel8 commented 3 years ago

Also don't allocate the extra StringBuilders in ScanPlainScalar unless needed. image

maxvoxel8 commented 3 years ago
maxvoxel8 commented 3 years ago

The left profile is before my changes, the middle profile is with 6f5e365, the right is with 5a168a5. image

maxvoxel8 commented 3 years ago

Speed up adding nodes when tracker is used. This is a performance penalty that only exists if tracker is assigned.

image

maxvoxel8 commented 3 years ago

Improve write performance by reducing allocation in AnalyzeScalar (ideally the StringLookaheadBuffer should also not be allocated, but that requires more changes). image

maxvoxel8 commented 3 years ago

Speed up YamlNode.DeepClone by not copying immutable ParserEvent values and by pre-allocating list size. Not sure why I was copying the events to begin with...

image

maxvoxel8 commented 3 years ago

@xoofx thanks for the merge, I do have another performance change I'm working on that I will make another PR for.