Utilities: single-lookup htmlTags updates in auto-break tag stripping#12647
Conversation
AutoBreakLineMoreThanTwoLines and AutoBreakLinePrivate collected stripped tags with ContainsKey + get + set - up to three hash lookups per tag inside per-character scanning loops. Route all three sites through an AddOrAppendHtmlTag helper using CollectionsMarshal.GetValueRefOrAddDefault on .NET 8+ (one lookup; null + tag handles the add case), with a TryGetValue fallback for netstandard2.1. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Please add BenchmarkDotNet numbers for performance PRs |
Benchmarking the auto-break tag-stripping loop showed no measurable gain from the GetValueRefOrAddDefault path (tag-heavy line 3031ns -> 3074ns, html 1182ns -> 1116ns, plain 392ns -> 388ns, identical allocations). The loop is dominated by the s.Remove() per tag, which reallocates and copies the whole string, so the dictionary update is rounding error. Keep the helper - it still removes three duplicated blocks - but with a single TryGetValue body instead of two framework-conditional paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Benchmarked this one with BenchmarkDotNet (net10.0, i7-1065G7) against a verbatim copy of the
No real win, and the case it most targets is marginally slower. The loop is dominated by So I pushed b8c1c81 keeping your For context, #12645 and #12646 did measure real gains (10-11% and 9-12% respectively) and are merged as-is. If you want a bigger win in this area, the |
Summary
AutoBreakLineMoreThanTwoLinesandAutoBreakLinePrivatestrip formatting tags into anhtmlTagsdictionary usingContainsKey+ get + set — up to three hash lookups per tag, inside per-character scanning loops that run for every auto-broken line.AddOrAppendHtmlTaghelper that usesCollectionsMarshal.GetValueRefOrAddDefaulton .NET 8+ — a single lookup for both the add and the append case (null + tagcovers a newly added key) — with aTryGetValuefallback for netstandard2.1.Test plan
dotnet build src/libse/LibSE.csprojsucceeds for both target frameworks (netstandard2.1 + net10.0)dotnet test tests/libse/LibSETests.csproj— all 574 tests pass (auto-break is covered by the existing suite)<i>/<font>and{\an8}-style tags and confirm tags are re-inserted at the same positions as before🤖 Generated with Claude Code