{"id":17008473,"url":"https://github.com/linkdotnet/stringbuilder","last_synced_at":"2026-02-19T10:13:11.998Z","repository":{"id":42371660,"uuid":"477381728","full_name":"linkdotnet/StringBuilder","owner":"linkdotnet","description":"A fast and low allocation StringBuilder for .NET.","archived":false,"fork":false,"pushed_at":"2025-05-06T07:51:36.000Z","size":969,"stargazers_count":100,"open_issues_count":2,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-16T08:04:47.359Z","etag":null,"topics":["csharp","dotnet","performance","rune","string","string-builder","stringbuilder","valuestringbuilder"],"latest_commit_sha":null,"homepage":"https://linkdotnet.github.io/StringBuilder/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linkdotnet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-03T15:24:50.000Z","updated_at":"2025-05-06T07:51:40.000Z","dependencies_parsed_at":"2023-11-07T17:26:23.466Z","dependency_job_id":"d5d343b0-3499-4f1f-a421-29ff7dd5a78f","html_url":"https://github.com/linkdotnet/StringBuilder","commit_stats":{"total_commits":478,"total_committers":5,"mean_commits":95.6,"dds":0.5,"last_synced_commit":"62dc8dfc893539824370480ac674f22bc148274a"},"previous_names":[],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FStringBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FStringBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FStringBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdotnet%2FStringBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdotnet","download_url":"https://codeload.github.com/linkdotnet/StringBuilder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493378,"owners_count":22080126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","performance","rune","string","string-builder","stringbuilder","valuestringbuilder"],"created_at":"2024-10-14T05:28:22.343Z","updated_at":"2026-02-19T10:13:11.944Z","avatar_url":"https://github.com/linkdotnet.png","language":"C#","readme":"# StringBuilder\n\n[![.NET](https://github.com/linkdotnet/StringBuilder/actions/workflows/dotnet.yml/badge.svg)](https://github.com/linkdotnet/StringBuilder/actions/workflows/dotnet.yml)\n[![Nuget](https://img.shields.io/nuget/dt/LinkDotNet.StringBuilder?style=flat-square)](https://www.nuget.org/packages/LinkDotNet.StringBuilder/)\n[![GitHub tag](https://img.shields.io/github/v/tag/linkdotnet/StringBuilder?include_prereleases\u0026logo=github\u0026style=flat-square)](https://github.com/linkdotnet/StringBuilder/releases)\n\nA fast and low allocation StringBuilder for .NET.\n\n## Getting Started\nInstall the package:\n\u003e PM\u003e Install-Package LinkDotNet.StringBuilder\n\nAfterward, use the package as follow:\n```csharp\nusing LinkDotNet.StringBuilder; // Namespace of the package\n\nusing ValueStringBuilder stringBuilder = new();\nstringBuilder.AppendLine(\"Hello World\");\n\nstring result = stringBuilder.ToString();\n```\n\nThere are also smaller helper functions, which enable you to use `ValueStringBuilder` without any instance:\n```csharp\nstring result1 = ValueStringBuilder.Concat(\"Hello \", \"World\"); // \"Hello World\"\nstring result2 = ValueStringBuilder.Concat(\"Hello\", 1, 2, 3, \"!\"); // \"Hello123!\"\n```\n\nBy default, `ValueStringBuilder` uses a rented buffer from `ArrayPool\u003cchar\u003e.Shared`.\nYou can avoid renting overhead with an initially stack-allocated buffer:\n```csharp\nusing ValueStringBuilder stringBuilder = new(stackalloc char[128]);\n```\nNote that this will prevent you from returning `stringBuilder` or assigning it to an `out` parameter.\n\n## What does it solve?\nThe dotnet version of the `StringBuilder` is an all-purpose version that normally fits a wide variety of needs.\nBut sometimes, low allocation is key. Therefore I created the `ValueStringBuilder`. It is not a class but a `ref struct` that tries to allocate as little as possible.\nIf you want to know how the `ValueStringBuilder` works and why it uses allocations and is even faster, check out [this](https://steven-giesel.com/blogPost/4cada9a7-c462-4133-ad7f-e8b671987896) blog post.\nThe blog goes into a bit more in detail about how it works with a simplistic version of the `ValueStringBuilder`.\n\n## What doesn't it solve?\nThe library is not meant as a general replacement for the `StringBuilder` built into .NET. You can head over to the documentation and read about the [\"Known limitations\"](https://linkdotnet.github.io/StringBuilder/articles/known_limitations.html).\nThe library works best for a small to medium length strings (not hundreds of thousands of characters, even though it can be still faster and performs fewer allocations). At any time, you can convert the `ValueStringBuilder` to a \"normal\" `StringBuilder` and vice versa.\n\nThe normal use case is to concatenate strings in a hot path where the goal is to put as minimal pressure on the GC as possible.\n\n## Documentation\nMore detailed documentation can be found [here](https://linkdotnet.github.io/StringBuilder). It is really important to understand how the `ValueStringBuilder` works so that you did not run into weird situations where performance/allocations can even rise.\n\n## Benchmark\n\nThe following table compares the built-in `StringBuilder` and this library's `ValueStringBuilder`:\n\n```no-class\nBenchmarkDotNet v0.14.0, macOS Sequoia 15.3.1 (24D70) [Darwin 24.3.0]\nApple M2 Pro, 1 CPU, 12 logical and 12 physical cores\n.NET SDK 9.0.200\n  [Host]     : .NET 9.0.2 (9.0.225.6610), Arm64 RyuJIT AdvSIMD\n  DefaultJob : .NET 9.0.2 (9.0.225.6610), Arm64 RyuJIT AdvSIMD\n\n\n| Method              | Mean      | Error    | StdDev   | Ratio | Gen0   | Allocated | Alloc Ratio |\n|-------------------- |----------:|---------:|---------:|------:|-------:|----------:|------------:|\n| DotNetStringBuilder | 126.74 ns | 0.714 ns | 0.667 ns |  1.00 | 0.1779 |    1488 B |        1.00 |\n| ValueStringBuilder  |  95.69 ns | 0.118 ns | 0.110 ns |  0.76 | 0.0669 |     560 B |        0.38 |\n```\n\nFor more comparisons, check the documentation.\n\nAnother benchmark shows that `ValueStringBuilder` allocates less memory when appending value types (such as `int` and `double`):\n\n```no-class\n| Method                         | Mean     | Error   | StdDev  | Gen0   | Gen1   | Allocated |\n|------------------------------- |---------:|--------:|--------:|-------:|-------:|----------:|\n| ValueStringBuilderAppendFormat | 821.7 ns | 1.29 ns | 1.14 ns | 0.4330 |      - |   3.54 KB |\n| StringBuilderAppendFormat      | 741.5 ns | 5.58 ns | 5.22 ns | 0.9909 | 0.0057 |    8.1 KB |\n```\n\nCheck out the [Benchmark](tests/LinkDotNet.StringBuilder.Benchmarks) for a more detailed comparison and setup.\n\n## Support \u0026 Contributing\n\nThanks to all [contributors](https://github.com/linkdotnet/StringBuilder/graphs/contributors) and people that are creating bug-reports and valuable input:\n\n\u003ca href=\"https://github.com/linkdotnet/StringBuilder/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=linkdotnet/StringBuilder\" alt=\"Supporters\" /\u003e\n\u003c/a\u003e","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdotnet%2Fstringbuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdotnet%2Fstringbuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdotnet%2Fstringbuilder/lists"}