Skip to content

Slower than .NET ValueStringBuilder & two ideas how to fix it #135

@alex-jitbit

Description

@alex-jitbit

I benchmarked ZString against .NET built-in ValueStringBuilder (not exposed publicly but we can steal extract the sources from https://source.dot.net/#System.Text.RegularExpressions/src/libraries/Common/src/System/Text/ValueStringBuilder.cs,42c1e0215cccb8b1 )

For some cases (when knowing length upfront and when appending 1-char strings) ValueStringBuilder is much faster.

Steps needed:

  1. We should allow passing capacity to CreateStringBuilder to preallocate buffer if length is known
  2. We should use an optimized path when Append is called with a 1-character string. Look at how ValueStringBuilder does it. If length is 1 it just sets buffer[pos++] = inputString[0] which is extremely fast, much faster than calling .CopyTo. https://source.dot.net/#System.Text.RegularExpressions/src/libraries/Common/src/System/Text/ValueStringBuilder.cs,42c1e0215cccb8b1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions