Skip to content

Improvement#104

Merged
prozolic merged 2 commits into
mainfrom
refactoring
May 11, 2026
Merged

Improvement#104
prozolic merged 2 commits into
mainfrom
refactoring

Conversation

@prozolic
Copy link
Copy Markdown
Owner

This PR change this following.

  • 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 size

 - 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
Copilot AI review requested due to automatic review settings May 11, 2026 15:54
@prozolic prozolic changed the title Improvement this following Improvement May 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • TryGetValueCore uses if ((uint)index > (uint)entries.Length) as an out-of-bounds guard, but index == entries.Length is already out of range and will fall through to entries[index]. Change the check to >= entries.Length to 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.

Comment thread src/CsToml/Utility/SpanWriter.cs
Comment thread src/CsToml/TomlCodes.cs
Comment thread src/CsToml/Values/TomlTableNodeDictionary.cs
Comment thread src/CsToml/Values/TomlTableNodeDictionary.cs
@prozolic prozolic merged commit 883d4cc into main May 11, 2026
1 check passed
@prozolic prozolic deleted the refactoring branch May 11, 2026 16:14
@prozolic prozolic mentioned this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants