Improvement#104
Merged
Merged
Conversation
- Suppress inlining optimization on exception helper methods - Improve out-of-bounds access safety using Debug.Assert and At extension methods - Speed up decimal digit counting - Optimize binary number parsing in TomlBinaryInteger - Optimize UTF-8 conversion buffers
Contributor
There was a problem hiding this comment.
Pull request overview
This PR focuses on performance and safety-oriented internal optimizations across CsToml’s parsing/serialization pipeline, including numeric formatting/parsing, UTF-8 conversions, dictionary traversal, and exception helper behavior.
Changes:
- Adjust exception helper methods to discourage inlining, and introduce/expand debug-time bounds assertions via
At(...). - Optimize integer digit counting and binary integer parsing; update writer code paths to use the new digit counting routine.
- Tune UTF-8 conversion buffer sizing and apply small hot-path micro-optimizations (e.g., unsigned bounds checks).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CsToml/Values/TomlTableNodeDictionary.cs | Updates collision/bounds guards and enumerator null-handling in the internal table-node dictionary. |
| src/CsToml/Values/TomlInteger.cs | Optimizes binary integer parsing implementation. |
| src/CsToml/Values/TomlArray.cs | Minor formatting tweaks and unsigned bounds checks in enumerators. |
| src/CsToml/Utility/Utf8Helper.cs | Adjusts UTF-8 buffer sizing using Encoding.UTF8 helpers. |
| src/CsToml/Utility/SpanWriter.cs | Refactors SpanWriter storage/write logic (currently introduces a compilation issue). |
| src/CsToml/Utf8TomlDocumentWriter.cs | Switches digit counting calls to CountDigitsForInt64 and applies small formatting cleanups. |
| src/CsToml/TomlCodes.cs | Adds CountDigitsForInt64, uses At(...) for table lookups, and introduces whitespace byte spans (currently introduces a compilation issue). |
| src/CsToml/Extension/CollectionExtensions.cs | Implements At(...) with Debug.Assert bounds checks and unchecked access. |
| src/CsToml/Error/ExceptionHelper.cs | Changes throw helpers to [NoInlining] and fixes ThrowDeserializationFailed to include the message. |
Comments suppressed due to low confidence (1)
src/CsToml/Values/TomlTableNodeDictionary.cs:178
TryGetValueCoreusesif ((uint)index > (uint)entries.Length)as an out-of-bounds guard, butindex == entries.Lengthis already out of range and will fall through toentries[index]. Change the check to>= entries.Lengthto prevent potential out-of-range access when buckets/next pointers are corrupted.
do
{
if ((uint)index > (uint)entries.Length)
{
value = null;
return false;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merged
This was referenced May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR change this following.
TomlBinaryInteger