Release 1.0.1 - #219
Open
FlorianRappl wants to merge 7 commits into
Open
Conversation
Profiling getComputedStyle over a realistic document (ultra/ETW, 8190 Hz) showed the cascade path dominated by work that was repeated per element: - StyleCollection held a lazy sheet sequence, so every enumeration re-walked the whole DOM looking for style/link elements. The collection is enumerated once per element AND once per ancestor, making StyleExtensions.GetStyleSheets 48% of the profile on its own. The sequence is now walked once and the flattened matching rules cached for the lifetime of the collection, which spans a single cascade or render pass. - CssStyleRule.TryMatch sorted its selector list by descending specificity on every match attempt (29% of its own subtree). The list only changes when the selector is assigned, so it is sorted there instead. OrderByDescending is stable, so equal-specificity ordering is unchanged. - SortBySpecificity built Tuple objects through SelectMany/OrderBy. Under shared generics LINQ's internal ToArray spent 16.6% of the whole profile in array covariance checks (CastHelpers.StelemRef). Replaced with a list of structs plus an index tie-break that reproduces OrderBy's stability exactly. - TryMatch re-read DocumentElement per rule per element because scope was always passed as null; it is now resolved once per element. Also drops a per-call filtered list and LINQ closures from TryCreateShorthand on the parsing path. Measured with BenchmarkDotNet (MediumRun, idle machine), baseline = devel: ComputedStyle 23,169 us -> 5,100 us (4.5x) 25.19 MB -> 1.41 MB RenderTree 29,828 us -> 7,288 us (4.1x) 56.25 MB -> 5.25 MB Stylesheet parsing throughput is unchanged (all deltas within error bars); its allocations drop 2-15% across the eight real-world sample sheets. Adds CssCascadeBenchmarks to cover the styling side, which had no benchmark. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Speed up cascade resolution by ~4.5x
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.
Types of Changes
Prerequisites
Please make sure you can check the following two boxes:
Contribution Type
What types of changes does your code introduce? Put an
xin all the boxes that apply:Description
CSM 101 (Rest as in the CHANGELOG)