-
-
Notifications
You must be signed in to change notification settings - Fork 150
perf(bridge): CSS style engine optimizations + invalidation fixes #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
1472d09 to
fc2d316
Compare
andycall
approved these changes
Jan 16, 2026
- Cache author stylesheets in DOM order via StyleEngine and match against that list to preserve cascade semantics and avoid matching inline/link sheets twice. - Reuse cached UA default HTML stylesheet RuleSet instead of rebuilding per match. - Track pseudo-element matches during normal collection; only resolve ::before/::after when `content` is present, prefilter pseudo selector buckets, and clear stale pseudo styles via a per-element sent mask. - Initialize Document URL from script/module sourceURL (and Dart-provided URL for parseHTML/bytecode eval) so @import/url() never leak about:* bases across the bridge. - Add gtests for pseudo style gating.
UA (user-agent) default styles are now provided by the Dart engine only. This removes the native UA stylesheet pipeline from the C++ bridge: - Drop CSSDefaultStyleSheets and bundled html.css/quirks.css resources - Remove UA rule matching from StyleResolver / ElementRuleCollector - Remove CMake CSS header generation and source list entry - Update tests to stop resetting UA stylesheets
Blink-style declared-value recalc was rebuilding MediaQueryEvaluator for every element during MatchAuthorRules, which is expensive because it constructs dynamic MediaValues. Changes: - Reuse cached author-sheet RuleSets via StyleSheetContents::GetRuleSetShared() and only call EnsureRuleSet() (and thus create a MediaQueryEvaluator) on cache miss. - Lazily construct a single MediaQueryEvaluator per MatchAuthorRules call instead of per element. - Make MatchRequest store the common single RuleSet inline and iterate via ForEachRuleSet() to avoid per-match vector allocations. Tests: - node scripts/run_bridge_unit_test.js (fails: StyleEngineTest.SiblingInvalidationDirectAdjacentOnInsertion)
- Cache viewport width/height + DPR in ExecutingContext and feed via Page resize/DPR callbacks. MediaValues reads cached values first to avoid synchronous GetBindingProperty during MQ eval. - Optimize cascade construction by avoiding per-property stable_sort in StyleCascade::AnalyzeMatchResult. - Speed up selector rule collection: use std::sort (cascade_order is unique) and avoid allocating typed-only ID buckets. - Minor: assign MatchResult directly into StyleCascade in StyleEngine. Also remove noisy style update timing log previously used for profiling. Tests: - cmake --build bridge/cmake-build-macos-arm64 -j 8 - bridge/build/macos/lib/arm64/webf_css_unittests '--gtest_filter=StyleCascadeTest.*' # Conflicts: # webf/example/macos/Runner.xcodeproj/project.pbxproj
…mments - Update cascade origin documentation to provide clearer implementation details. - Adjust bit manipulation logic for important origins to simplify flipping behavior while preserving transition bit. - Refactor constants and inline methods for improved readability and consistency.
…ld options - Eliminated WEBF_LOG_* macros and conditional logging logic. - Simplified CMakeLists.txt by removing log category definitions and build-time switches. - Streamlined logging implementation for maintenance and readability.
- Bridge: cache preferred color scheme in ExecutingContext and reuse it in MediaValuesDynamic::PreferredColorScheme - Bridge: update cached scheme on nativeOnColorSchemeChanged to keep prefers-color-scheme media queries consistent - Dart: on attach/brightness change, dispatch ColorSchemeChangeEvent and notify native Blink when not overridden - Dart: make WebFController.isDarkMode fall back to PlatformDispatcher for consistent system brightness - Example: keep DayNightSwitcherIcon in sync (app toggle sets override; system toggle clears override to null) - macOS example: embed objective_c.framework for plugin linkage
…anges - Ensure descendants of elements transitioning from `display:none` to visible recalculate styles to pick up inline styles and render correctly. - Add handling for `IsDisplayNoneForStyleInvalidation` to trigger subtree recalculation and clear subtree flags.
- Dropped redundant `nativeOnColorSchemeChanged` call, as platform brightness changes no longer notify native Blink.
…equirement - Ensure sibling invalidations occur even when restyle flags are not set by WebF. - Adjust logic to skip unnecessary checks for indirect/direct adjacent rules before scheduling invalidations. - Add safe handling for inserting/removing sibling elements when selector matching is incomplete.
And run generate_ios_mirror_ccs.js --fix - Added logic to detect and remove orphan wrappers no longer matching source files or configuration. - Extended wrapper support to include `.mm` files. - Updated `--fix` flag to remove orphans and prune empty directories. - Improved dry-run mode to clarify removal actions without modifying files.
9eda278 to
00516c5
Compare
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.
Motivation
This branch focuses on CSS correctness and performance in the bridge style engine, especially around stylesheet ordering/base URL, media-query evaluation, and style invalidation.
What changed
CSS correctness
display:noneto visible by forcing subtree style recalculation (prevents descendants from keeping stale styles).Performance
MediaQueryEvaluatorconstruction during rule matching; reuse evaluator via match request context.Refactors / cleanup
Commits (in order)
fix(css): preserve author sheet DOM order and base URLrefactor(bridge): remove UA stylesheet handlingperf(bridge): avoid per-element MediaQueryEvaluator in rule matchingperf(bridge): speed up resize media-query style recalcrefactor(css): clarify cascade origin bit manipulation and improve commentsrefactor(logging): remove per-category logging system and related build optionsfix(theme): sync system color scheme and overridesfix: buildfix(css): recompute subtree styles after display:none -> visible changesRisk / compatibility notes
bridge/core/css/style_engine.cc; please pay extra attention to regressions in selector matching, invalidation, and stylesheet ordering.Testing
node scripts/run_bridge_unit_test.js).