Repository navigation
Read the quirks mode without reflection - #268
Merged
FlorianRappl merged 2 commits intoNov 5, 2026
Merged
Conversation
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.
The quirks mode checks in
PresentationalHints.GetDeclarations(once per element) and inCssBuilder.CreateDeclarationWithreadIDocument.CompatMode. In AngleSharp that getter maps the quirks mode to its string through reflection on every read (QuirksMode.GetCompatiblity():GetField+GetCustomAttribute), which costs more than the rest of an element's cascade. In a profile ofGetInnerTextit was the largest single item.This PR reads the mode directly where AngleSharp exposes it:
QuirksMode.Onmaps to"BackCompat";Limited(limited quirks) maps to"CSS1Compat", as before. OtherIDocumentimplementations still go throughCompatMode.CompatModereads the same field, so I found no reason. If you'd rather stay on the publicIDocumentAPI, the alternative is caching the result per document - happy to switch.LimitedQuirksModeHasNoneOfThem: a limited quirks document (XHTML 1.0 Transitional doctype) gets neither the quirks of the presentational hints nor the unit-less lengths of the parser. It fails whenLimitedis treated as quirks.Benchmarks against devel (BenchmarkDotNet, 6 alternating rounds, pinned to the performance cores):
Render(), selector-heavy documentRender(), real-world documentThe
Render()real-world number is a GC artifact, not extra work: the slow rounds are exactly those in which the candidate ran a gen2 collection (one every 8 renders); the baseline had none. The output and the element count are the same, and allocations are slightly lower. A probe without BenchmarkDotNet's forced collections between iterations measured −0.5% / −2.8% for it.🤖 Generated with Claude Code