Skip to content

Optimize ToString() performance via JIT bounds-check elimination and update documentation#38

Merged
Seramis merged 3 commits intoByteAether:mainfrom
Seramis:ToString_Optimization
Mar 25, 2026
Merged

Optimize ToString() performance via JIT bounds-check elimination and update documentation#38
Seramis merged 3 commits intoByteAether:mainfrom
Seramis:ToString_Optimization

Conversation

@Seramis
Copy link
Copy Markdown
Member

@Seramis Seramis commented Mar 25, 2026

Description

This PR introduces a JIT optimization in the Fill<T> method to improve ToString() performance and synchronizes project documentation with recent benchmarks.

  • JIT Optimization: Added a guard clause to Fill<T> that validates Span and map lengths upfront. This hints to the JIT compiler that subsequent indexed accesses are safe, effectively eliminating redundant runtime bounds-checking for the 26 character assignments.
  • Documentation: Updated README.md and PACKAGE.md with the latest benchmark results and clearer feature definitions to better reflect the library's current features.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Other (please specify): Performance optimization

Checklist

  • The PR is submitted to the correct branch (main).
  • My code follows the project's coding style. (.editorconfig)
  • I have commented my code, particularly in hard-to-understand areas and public interfaces.
  • I have added or updated tests for the changes I made.
  • All new and existing tests passed.
  • I have updated the documentation where applicable.

Additional Notes

The Fill<T> method is a hot path for ULID string encoding. By ensuring span.Length is at least UlidStringLength and map.Length is at least 32 ($1 \ll 5$), the compiler can optimize the massive block of assignments into a linear sequence of instructions without branching for safety checks at every index.

Seramis added 3 commits March 25, 2026 10:53
…dd `AsByteSpan()` benchmark along with `ToByteArray()` benchmarks.
…ss, and lock-free synchronization details. Update PACKAGE.md as necessary.
@Seramis Seramis self-assigned this Mar 25, 2026
@Seramis Seramis merged commit 9b896e6 into ByteAether:main Mar 25, 2026
5 checks passed
@Seramis Seramis deleted the ToString_Optimization branch March 25, 2026 09:09
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.

1 participant