[PR #606] Improvements when TrackTrivia is disabled #1141

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

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

State: closed
Merged: Yes


A few changes mainly around reducing the overhead of the TrackTrivia impl even when it isn't requested:

  • Span.IndexOfAny('\r', '\n') in LineReader
  • Moving all trivia properties to lazy-allocated objects to reduce the size of Syntax objects.
  • Avoiding work that's only relevant for trivia when it's not needed

I was playing around with two markdown documents for these:

  • The Markdig readme
  • A random doc article

Before

Method Mean Error StdDev Gen 0 Gen 1 Allocated
MarkdigReadme 315.18 us 0.695 us 1.019 us 36.1328 12.2070 169 KB
TracingArticle 43.94 us 0.080 us 0.115 us 5.6763 0.3052 23 KB

After

Method Mean Error StdDev Gen 0 Gen 1 Allocated
MarkdigReadme 305.87 us 3.347 us 5.010 us 32.7148 10.7422 136 KB
TracingArticle 41.33 us 0.136 us 0.200 us 4.4556 - 18 KB
**Original Pull Request:** https://github.com/xoofx/markdig/pull/606 **State:** closed **Merged:** Yes --- A few changes mainly around reducing the overhead of the `TrackTrivia` impl even when it isn't requested: - `Span.IndexOfAny('\r', '\n')` in `LineReader` - Moving all trivia properties to lazy-allocated objects to reduce the size of `Syntax` objects. - Avoiding work that's only relevant for trivia when it's not needed I was playing around with two markdown documents for these: - The Markdig readme - A random doc [article](https://github.com/microsoft/reverse-proxy/blob/main/docs/docfx/articles/distributed-tracing.md) Before | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated | |--------------- |----------:|---------:|---------:|--------:|--------:|----------:| | MarkdigReadme | 315.18 us | 0.695 us | 1.019 us | 36.1328 | 12.2070 | 169 KB | | TracingArticle | 43.94 us | 0.080 us | 0.115 us | 5.6763 | 0.3052 | 23 KB | After | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated | |--------------- |----------:|---------:|---------:|--------:|--------:|----------:| | MarkdigReadme | 305.87 us | 3.347 us | 5.010 us | 32.7148 | 10.7422 | 136 KB | | TracingArticle | 41.33 us | 0.136 us | 0.200 us | 4.4556 | - | 18 KB |
claunia added the pull-request label 2026-01-29 14:50:18 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1141