[PR #377] [MERGED] 10% time and 50% memory improvement #978

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

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/377
Author: @MihaZupan
Created: 10/14/2019
Status: Merged
Merged: 10/15/2019
Merged by: @xoofx

Base: masterHead: allocation-reductions


📝 Commits (10+)

  • 253be5c Cache HtmlRenderers in AutoIdentifier Extension
  • 606556b Use Write(Span) on NetCore
  • afe4308 Cache HtmlRenderer on Pipeline for ToHtml(string, Pipeline)
  • 76c3e88 Estimate LineCount from text Length to minimize List resizes
  • aefad21 Cache StringLine[]s in StringLineGroup with a custom ArrayPool
  • f73cbe4 Resize LineOffsets to sufficient Capacity before adding items
  • ed5eea5 Cache List in AutoLinkParser
  • 0987fab Seal internal types
  • 8913341 Mark Readonly structs as Readonly
  • 2761e36 Optimize StringSlice primitives

📊 Changes

28 files changed (+567 additions, -309 deletions)

View changed files

📝 appveyor.yml (+1 -1)
📝 changelog.md (+1 -0)
📝 src/Markdig.Tests/TestStringSliceList.cs (+12 -2)
📝 src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs (+24 -9)
📝 src/Markdig/Extensions/AutoLinks/AutoLinkParser.cs (+164 -156)
📝 src/Markdig/Extensions/SmartyPants/SmartyPantsInlineParser.cs (+5 -5)
📝 src/Markdig/Extensions/Tables/GridTableParser.cs (+2 -2)
📝 src/Markdig/Extensions/Tables/GridTableState.cs (+1 -1)
📝 src/Markdig/Helpers/CharHelper.cs (+13 -10)
📝 src/Markdig/Helpers/CompactPrefixTree.cs (+1 -1)
src/Markdig/Helpers/CustomArrayPool.cs (+86 -0)
📝 src/Markdig/Helpers/HtmlHelper.cs (+1 -1)
📝 src/Markdig/Helpers/StringBuilderExtensions.cs (+8 -1)
📝 src/Markdig/Helpers/StringLine.cs (+1 -1)
📝 src/Markdig/Helpers/StringLineGroup.cs (+32 -19)
📝 src/Markdig/Helpers/StringSlice.cs (+105 -76)
📝 src/Markdig/Markdig.targets (+1 -1)
📝 src/Markdig/Markdown.cs (+12 -3)
📝 src/Markdig/MarkdownPipeline.cs (+38 -1)
📝 src/Markdig/Parsers/BlockProcessor.cs (+6 -1)

...and 8 more files

📄 Description

A bunch of random optimizations.

Most interesting (and responsible for perf) ones to look at are:
253be5c afe4308 aefad21

I was mainly playing whack-a-mole with memory allocations, time improvement comes mainly from 253be5c.


🔄 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/377 **Author:** [@MihaZupan](https://github.com/MihaZupan) **Created:** 10/14/2019 **Status:** ✅ Merged **Merged:** 10/15/2019 **Merged by:** [@xoofx](https://github.com/xoofx) **Base:** `master` ← **Head:** `allocation-reductions` --- ### 📝 Commits (10+) - [`253be5c`](https://github.com/xoofx/markdig/commit/253be5c362d9e5df23b6f9da53b3f0753742a14a) Cache HtmlRenderers in AutoIdentifier Extension - [`606556b`](https://github.com/xoofx/markdig/commit/606556b6925a0be26a01eba09291af8a15aada3d) Use Write(Span) on NetCore - [`afe4308`](https://github.com/xoofx/markdig/commit/afe4308e918b8afa5d5359d2fab270b4621ef3ab) Cache HtmlRenderer on Pipeline for ToHtml(string, Pipeline) - [`76c3e88`](https://github.com/xoofx/markdig/commit/76c3e88c588e54cda02df70780accff65daf1eb9) Estimate LineCount from text Length to minimize List resizes - [`aefad21`](https://github.com/xoofx/markdig/commit/aefad219cf875ce21df2842f11e25b8569def663) Cache StringLine[]s in StringLineGroup with a custom ArrayPool - [`f73cbe4`](https://github.com/xoofx/markdig/commit/f73cbe4e7604ae246ec290dcc19170cb25ab8f5f) Resize LineOffsets to sufficient Capacity before adding items - [`ed5eea5`](https://github.com/xoofx/markdig/commit/ed5eea5e27182e1e45e26492f17d32187ab33230) Cache List<char> in AutoLinkParser - [`0987fab`](https://github.com/xoofx/markdig/commit/0987fab6f2887af1ed1bda49573e0ea6870038d7) Seal internal types - [`8913341`](https://github.com/xoofx/markdig/commit/891334134c3e3b67555f220c778fd422569576a2) Mark Readonly structs as Readonly - [`2761e36`](https://github.com/xoofx/markdig/commit/2761e36b6ba5b1b6a8e25c3c53ecbf63d3556062) Optimize StringSlice primitives ### 📊 Changes **28 files changed** (+567 additions, -309 deletions) <details> <summary>View changed files</summary> 📝 `appveyor.yml` (+1 -1) 📝 `changelog.md` (+1 -0) 📝 `src/Markdig.Tests/TestStringSliceList.cs` (+12 -2) 📝 `src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs` (+24 -9) 📝 `src/Markdig/Extensions/AutoLinks/AutoLinkParser.cs` (+164 -156) 📝 `src/Markdig/Extensions/SmartyPants/SmartyPantsInlineParser.cs` (+5 -5) 📝 `src/Markdig/Extensions/Tables/GridTableParser.cs` (+2 -2) 📝 `src/Markdig/Extensions/Tables/GridTableState.cs` (+1 -1) 📝 `src/Markdig/Helpers/CharHelper.cs` (+13 -10) 📝 `src/Markdig/Helpers/CompactPrefixTree.cs` (+1 -1) ➕ `src/Markdig/Helpers/CustomArrayPool.cs` (+86 -0) 📝 `src/Markdig/Helpers/HtmlHelper.cs` (+1 -1) 📝 `src/Markdig/Helpers/StringBuilderExtensions.cs` (+8 -1) 📝 `src/Markdig/Helpers/StringLine.cs` (+1 -1) 📝 `src/Markdig/Helpers/StringLineGroup.cs` (+32 -19) 📝 `src/Markdig/Helpers/StringSlice.cs` (+105 -76) 📝 `src/Markdig/Markdig.targets` (+1 -1) 📝 `src/Markdig/Markdown.cs` (+12 -3) 📝 `src/Markdig/MarkdownPipeline.cs` (+38 -1) 📝 `src/Markdig/Parsers/BlockProcessor.cs` (+6 -1) _...and 8 more files_ </details> ### 📄 Description A bunch of random optimizations. Most interesting (and responsible for perf) ones to look at are: 253be5c afe4308 aefad21 I was mainly playing whack-a-mole with memory allocations, time improvement comes mainly from 253be5c. --- <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:48:06 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#978