[PR #608] Some CPU improvements #1142

Open
opened 2026-01-29 14:50:19 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/xoofx/markdig/pull/608

State: closed
Merged: Yes


  • Caching the FencedCodeBlock.InfoString & language-prefixed strings
  • Using ValueStringBuilder over StringBuilderCache.Local()
  • Avoiding the cost of type checks & casting for ContainerBlock, LeafBlock, ParagraphBlock and ContainerInline by setting flags on the base type instead (this is a ~5% CPU win by removing S.R.CompilerServices.CastHelpers.IsInstanceOfClass).
  • Improved StringLineGroup.NextChar - very hot method for LinkHelper

Parsing this document with PreciseSourceLocation:

Before

Method SourceText Mean Error StdDev Gen 0 Allocated
Parse TracingArticle 42.77 us 0.232 us 0.332 us 4.4556 18 KB

After

Method SourceText Mean Error StdDev Gen 0 Allocated
Parse TracingArticle 37.39 us 0.215 us 0.309 us 4.3945 18 KB
**Original Pull Request:** https://github.com/xoofx/markdig/pull/608 **State:** closed **Merged:** Yes --- - Caching the `FencedCodeBlock.InfoString` & language-prefixed strings - Using `ValueStringBuilder` over `StringBuilderCache.Local()` - Avoiding the cost of type checks & casting for `ContainerBlock`, `LeafBlock`, `ParagraphBlock` and `ContainerInline` by setting flags on the base type instead (this is a ~5% CPU win by removing [`S.R.CompilerServices.CastHelpers.IsInstanceOfClass`](https://github.com/dotnet/runtime/blob/2f13361ba7d4cef84acae24751a3c367c1a6ab89/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs#L277)). - Improved `StringLineGroup.NextChar` - very hot method for `LinkHelper` Parsing [this document](https://github.com/microsoft/reverse-proxy/blob/main/docs/docfx/articles/distributed-tracing.md) with `PreciseSourceLocation`: Before | Method | SourceText | Mean | Error | StdDev | Gen 0 | Allocated | |------- |--------------- |---------:|---------:|---------:|-------:|----------:| | Parse | TracingArticle | 42.77 us | 0.232 us | 0.332 us | 4.4556 | 18 KB | After | Method | SourceText | Mean | Error | StdDev | Gen 0 | Allocated | |------- |--------------- |---------:|---------:|---------:|-------:|----------:| | Parse | TracingArticle | 37.39 us | 0.215 us | 0.309 us | 4.3945 | 18 KB |
claunia added the pull-request label 2026-01-29 14:50:19 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1142