[Repo Assist] perf: avoid ToCharArray allocations in TextConversions, HtmlParser, HtmlCssSelectors, HtmlOperations#1735
Draft
github-actions[bot] wants to merge 2 commits intomainfrom
Conversation
…tmlCssSelectors, HtmlOperations - TextConversions.RemoveAdorners: replace ToCharArray()+Array.filter with a StringBuilder loop; avoids two intermediate char[] allocations (ToCharArray result + filtered result) on the hot path for every number/date parse attempt - HtmlParser: replace ToCharArray()|>Array.rev string reversal with Array.init using direct index arithmetic; avoids ToCharArray allocation for malformed end-tag detection (e.g. <li></il>) - HtmlCssSelectors.StartsWith: remove ToCharArray(); compare list against string directly via Seq.compareWith (string is IEnumerable<char>) - HtmlCssSelectors.TokenStr: replace ToCharArray()|>Array.toList with List.ofSeq - HtmlCssSelectors.Tokenize: replace ToCharArray()|>Array.toList with List.ofSeq - HtmlOperations AttributeContainsPrefix: remove ToCharArray() before Seq.skipWhile since string is already IEnumerable<char> Co-authored-by: Copilot <[email protected]>
4 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.
Continues the series of allocation-reduction PRs (#1725, #1728, #1729, #1733) by eliminating remaining
ToCharArray()calls that create unnecessary intermediate allocations.Changes
TextConversions.RemoveAdorners(hotpath)The slow path for removing currency/percentage adorners used
ToCharArray() |> Array.filter, allocating two char arrays before creating the final string. Replaced with aStringBuilderloop that iterates the string directly (string isIEnumerable<char>in .NET):This is called on every number/date parse attempt across CSV, JSON, and XML type inference.
HtmlParser— reversed-tag detectionThe malformed-end-tag check (
<li></il>) reversed a string viaToCharArray() |> Array.rev. Replaced withArray.initusing direct index arithmetic — avoidsToCharArray()and a second array for the reversed result.HtmlCssSelectors— three sitesStartsWithactive pattern: removedToCharArray()and compared thechar listdirectly against thestringviaSeq.compareWith(strings areIEnumerable<char>)TokenStractive pattern:s.ToCharArray() |> Array.toList→List.ofSeq sTokenizemethod:cssSelector.ToCharArray() |> Array.toList→List.ofSeq cssSelectorHtmlOperations— CSS attribute selectorv.ToCharArray() |> Seq.skipWhile ...→v |> Seq.skipWhile ...(direct string enumeration)Test Status
dotnet test tests/FSharp.Data.Core.Tests/— 2909 passed, 0 failed