Repository navigation
Build the parts of the render tree only when needed - #266
Open
michaelthyregod wants to merge 1 commit into
Open
michaelthyregod wants to merge 1 commit into
michaelthyregod wants to merge 1 commit into
Conversation
Every element of a render tree got its ::before and ::after cascaded and its specified style built, though most have no generated content and the specified style is rarely read (AngleSharp#262). - Cascade a pseudo-element only if a rule that may match it declares its content; rules such as *::before { display: inline } of the default sheet alone do not give it a box - Build the specified style of a render node on first read, from the one its parent had when it was built; it is published atomically - Add tests for the declared content, the reading order, rendering again below a parent, and concurrent first reads
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
The first step of the partial render tree from #262: the parts of a render node that are rarely needed are only built when they are.
Render()still returns the complete tree, with the same styles.GetInnerTexton the render tree (and building children on demand) follows in a separate PR.The change
::before/::after: a pseudo-element is only cascaded if a rule that may match it declarescontent. Checking for any matching rule would not help: the default sheet's*::before, *::after { display: inline }matches every element.StyleRuleIndexkeeps the pseudo-element rules declaringcontent(and those with nested rules, which may) in their own group, keyed like the others.SpecifiedStyleon first read, top-down without recursion. Children inherit from a copy-on-write copy of their parent's style as it was built, so modifying a parent'sSpecifiedStylestill does not reach its children.Render(element, parent)inherits the parent's current one, as before. The style is published withInterlocked.CompareExchange, so concurrent first reads get the same instance.GetCascadedStyle()of a rendered pseudo-element still returns its node's specified style.ElementRenderNode; the public one is unchanged).@mediarules, and content added through the CSSOM; specified styles in any reading order and after modifying the parent; rendering again below a modified parent; concurrent first reads (synchronised with aBarrier); the cascaded style of a pseudo-element.Benchmarks
Paired builds of the same benchmark code against
devel(0d5ea08), alternating which goes first each round. BenchmarkDotNet 0.15.8, net10.0, AngleSharp 1.9.0 for both, pinned to the performance cores of an Intel Core Ultra 7 165H. Median of 6 rounds:CssCascadeBenchmarks.RenderTreeCssCascadeBenchmarks.ComputedStyleCssCascadeBenchmarks.ParseInlineDeclarationsDeepTreeBenchmarks.InnerText, 100 / 500 levelsDeepTreeBenchmarks.IsVisible, 100 / 500 levelsRenderTreeis faster in every round (−10.8% to −18.3%). The other cases do not build a render tree; their rounds change sign and stay within the ±5% that single rounds of the same build differ by.ComputedStylebuilds the rule index on every call, which now has one more group: 0.8% more allocation.The CHANGELOG has no open version yet. Shall I add a line (e.g. "Improved rendering by building pseudo-elements and specified styles only when needed") once you open one, or do you prefer to write it?
🤖 Generated with Claude Code