[PR #499] [CLOSED] Random perf improvements #1066

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

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/499
Author: @MihaZupan
Created: 12/17/2020
Status: Closed

Base: masterHead: random-perf


📝 Commits (7)

  • f453545 Avoid minor allocations in ProcessInlines loop
  • ab358b5 Minor codegen improvements
  • 2af8b1f Cache default MarkdownPipeline
  • c776d18 Avoid delegate allocations in AutoIdentifierExtension
  • c8a467c Remove unnecessary indirection
  • 20f1ae2 Reduce the size of MarkdownObject by 1 pointer size
  • f8f3402 Cache HtmlRenderer also for custom TextWriters

📊 Changes

26 files changed (+430 additions, -319 deletions)

View changed files

📝 src/Markdig.Tests/TestMarkdigCoreApi.cs (+101 -62)
📝 src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs (+1 -1)
📝 src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs (+35 -23)
📝 src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs (+2 -2)
📝 src/Markdig/Extensions/SmartyPants/SmartyPantsInlineParser.cs (+1 -1)
📝 src/Markdig/Extensions/Tables/GridTableParser.cs (+7 -6)
📝 src/Markdig/Extensions/Tables/PipeTableParser.cs (+1 -1)
📝 src/Markdig/Extensions/Tables/TableHelper.cs (+2 -2)
📝 src/Markdig/Extensions/TaskLists/TaskListInlineParser.cs (+1 -1)
📝 src/Markdig/Helpers/HtmlHelper.cs (+8 -8)
📝 src/Markdig/Helpers/ICharIterator.cs (+12 -1)
📝 src/Markdig/Helpers/LinkHelper.cs (+8 -8)
📝 src/Markdig/Helpers/StringLineGroup.cs (+6 -2)
📝 src/Markdig/Helpers/StringSlice.cs (+11 -0)
📝 src/Markdig/Markdown.cs (+46 -38)
📝 src/Markdig/MarkdownPipeline.cs (+51 -16)
📝 src/Markdig/Parsers/BlockProcessor.cs (+1 -1)
📝 src/Markdig/Parsers/HtmlBlockParser.cs (+1 -1)
📝 src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs (+1 -1)
📝 src/Markdig/Parsers/Inlines/EscapeInlineParser.cs (+2 -2)

...and 6 more files

📄 Description

Codegen tweaks and allocation improvements.

Removing the overheads in the simple Markdown.ToHtml(...) case with the default pipeline.
For an empty string allocations go from 17.14 KB to 928 B and take 1/20th the time because of the default pipeline caching (2af8b1f) - means we're now benefiting from the Renderer caching from afe4308e91 in the basic use cases.

For c776d18 I was quite surprised how bad the compiler is at avoiding these allocations :/


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/xoofx/markdig/pull/499 **Author:** [@MihaZupan](https://github.com/MihaZupan) **Created:** 12/17/2020 **Status:** ❌ Closed **Base:** `master` ← **Head:** `random-perf` --- ### 📝 Commits (7) - [`f453545`](https://github.com/xoofx/markdig/commit/f453545c0213fd3c824056be5c36f6cd6849440e) Avoid minor allocations in ProcessInlines loop - [`ab358b5`](https://github.com/xoofx/markdig/commit/ab358b57888fe7bc79b74a15e7f7abfa52eae5f6) Minor codegen improvements - [`2af8b1f`](https://github.com/xoofx/markdig/commit/2af8b1f0414c78a46a983aedf5665a0233a50d17) Cache default MarkdownPipeline - [`c776d18`](https://github.com/xoofx/markdig/commit/c776d18dbd965a20fc363502749d361148373e0e) Avoid delegate allocations in AutoIdentifierExtension - [`c8a467c`](https://github.com/xoofx/markdig/commit/c8a467c5db74797a0e9b40e9fa2fa5e9d2aada16) Remove unnecessary indirection - [`20f1ae2`](https://github.com/xoofx/markdig/commit/20f1ae2c8f23cf8c7853f11c26285326a1c6e9e4) Reduce the size of MarkdownObject by 1 pointer size - [`f8f3402`](https://github.com/xoofx/markdig/commit/f8f3402f2f398dd229dfafc77f305f958629b926) Cache HtmlRenderer also for custom TextWriters ### 📊 Changes **26 files changed** (+430 additions, -319 deletions) <details> <summary>View changed files</summary> 📝 `src/Markdig.Tests/TestMarkdigCoreApi.cs` (+101 -62) 📝 `src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs` (+1 -1) 📝 `src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs` (+35 -23) 📝 `src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs` (+2 -2) 📝 `src/Markdig/Extensions/SmartyPants/SmartyPantsInlineParser.cs` (+1 -1) 📝 `src/Markdig/Extensions/Tables/GridTableParser.cs` (+7 -6) 📝 `src/Markdig/Extensions/Tables/PipeTableParser.cs` (+1 -1) 📝 `src/Markdig/Extensions/Tables/TableHelper.cs` (+2 -2) 📝 `src/Markdig/Extensions/TaskLists/TaskListInlineParser.cs` (+1 -1) 📝 `src/Markdig/Helpers/HtmlHelper.cs` (+8 -8) 📝 `src/Markdig/Helpers/ICharIterator.cs` (+12 -1) 📝 `src/Markdig/Helpers/LinkHelper.cs` (+8 -8) 📝 `src/Markdig/Helpers/StringLineGroup.cs` (+6 -2) 📝 `src/Markdig/Helpers/StringSlice.cs` (+11 -0) 📝 `src/Markdig/Markdown.cs` (+46 -38) 📝 `src/Markdig/MarkdownPipeline.cs` (+51 -16) 📝 `src/Markdig/Parsers/BlockProcessor.cs` (+1 -1) 📝 `src/Markdig/Parsers/HtmlBlockParser.cs` (+1 -1) 📝 `src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs` (+1 -1) 📝 `src/Markdig/Parsers/Inlines/EscapeInlineParser.cs` (+2 -2) _...and 6 more files_ </details> ### 📄 Description Codegen tweaks and allocation improvements. Removing the overheads in the simple `Markdown.ToHtml(...)` case with the default pipeline. For an empty string allocations go from 17.14 KB to 928 B and take 1/20th the time because of the default pipeline caching (2af8b1f) - means we're now benefiting from the Renderer caching from https://github.com/lunet-io/markdig/commit/afe4308e918b8afa5d5359d2fab270b4621ef3ab in the basic use cases. For c776d18 I was quite surprised how bad the compiler is at avoiding these allocations :/ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 14:49: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#1066