Conversation
…Map O(log n) Replace the F# Map<string, string> (O(log n) per lookup) with a Dictionary<string, string> (O(1) per lookup) for the ~2230 HTML named-entity table. Also introduce a static semiColonChars array to avoid allocating a new char[] on every call to TrimEnd inside the (|Number|Lookup|) active pattern. Bump version to 8.1.10. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
approved these changes
Apr 20, 2026
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Summary
HtmlCharRefs.refspreviously used an F#Map<string, string>, which gives O(log n) lookups over its ~2230 entries (≈ 11 string comparisons per lookup). This PR replaces it with aDictionary<string, string>initialised withStringComparer.Ordinal, giving O(1) lookups.A secondary micro-optimisation avoids allocating a new
char[]on every call toTrimEndinside the(|Number|Lookup|)active pattern by sharing a private staticsemiColonCharsarray.Root Cause
The entity table was populated with
|> Map.ofArray(F# persistent balanced-BST map). For HTML documents with many character references (e.g.&,<, etc.) every entity name is resolved via a tree traversal. ADictionarywith ordinal key comparison gives the same correct result with constant-time lookup.Changes
src/FSharp.Data.Html.Core/HtmlCharRefs.fsrefsEntriesrefs : Dictionary<string, string>from that array with capacity hint andStringComparer.Ordinalprivate semiColonChars = [| ';' |](reused byTrimEnd)defaultArg (refs.TryFind ref) refwithrefs.TryGetValuepattern matchRELEASE_NOTES.md— new 8.1.10 entrysrc/AssemblyInfo*.fs— regenerated with version 8.1.10.0Test Status
dotnet test tests/FSharp.Data.Core.Tests --configuration Release— 2957 passed, 0 faileddotnet fantomas --check src/FSharp.Data.Html.Core/HtmlCharRefs.fs— formatting compliant