Skip to content

Commit 34e3229

Browse files
authored
feat: optimize performance for recalculate styles. (#579)
Schedule and merge to avoid duplicated calculation of styles.
2 parents a77b382 + fd64918 commit 34e3229

File tree

3 files changed

+1
-33
lines changed

3 files changed

+1
-33
lines changed

webf/lib/src/bridge/ui_command.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ List<UICommand> nativeUICommandToDart(List<int> rawMemory, int commandLength, do
8484

8585
void execUICommands(WebFViewController view, List<UICommand> commands) {
8686
Map<int, bool> pendingStylePropertiesTargets = {};
87-
Set<int> pendingRecalculateTargets = {};
8887

8988
for(UICommand command in commands) {
9089
UICommandType commandType = command.type;
@@ -268,7 +267,6 @@ void execUICommands(WebFViewController view, List<UICommand> commands) {
268267
String key = nativeStringToString(nativeKey);
269268
freeNativeString(nativeKey);
270269
view.setAttribute(nativePtr.cast<NativeBindingObject>(), key, command.args);
271-
pendingRecalculateTargets.add(nativePtr.address);
272270
if (enableWebFProfileTracking) {
273271
WebFProfiler.instance.finishTrackUICommandStep();
274272
}
@@ -343,15 +341,6 @@ void execUICommands(WebFViewController view, List<UICommand> commands) {
343341
WebFProfiler.instance.startTrackUICommandStep('FlushUICommand.recalculateStyle');
344342
}
345343

346-
for (var address in pendingRecalculateTargets) {
347-
try {
348-
view.recalculateStyle(address);
349-
} catch (e, stack) {
350-
print('$e\n$stack');
351-
}
352-
}
353-
pendingRecalculateTargets.clear();
354-
355344
if (enableWebFProfileTracking) {
356345
WebFProfiler.instance.finishTrackUICommandStep();
357346
}

webf/lib/src/dom/element.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin
207207
updateRenderBoxModel();
208208
}
209209

210-
bool _needRecalculateStyle = false;
211-
212210
final ElementRuleCollector _elementRuleCollector = ElementRuleCollector();
213211

214212
Element(BindingContext? context) : super(NodeType.ELEMENT_NODE, context) {
@@ -1361,13 +1359,11 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin
13611359

13621360
@mustCallSuper
13631361
void setAttribute(String qualifiedName, String value) {
1364-
internalSetAttribute(qualifiedName, value);
13651362
ElementAttributeProperty? propertyHandler = _attributeProperties[qualifiedName];
13661363
if (propertyHandler != null && propertyHandler.setter != null) {
13671364
propertyHandler.setter!(value);
13681365
}
1369-
final isNeedRecalculate = _checkRecalculateStyle([qualifiedName]);
1370-
_needRecalculateStyle = _needRecalculateStyle || isNeedRecalculate;
1366+
internalSetAttribute(qualifiedName, value);
13711367
}
13721368

13731369
void internalSetAttribute(String qualifiedName, String value) {
@@ -1713,11 +1709,6 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin
17131709
// But it's necessary for SVG.
17141710
}
17151711

1716-
void tryRecalculateStyle({bool rebuildNested = false}) {
1717-
recalculateStyle(forceRecalculate: _needRecalculateStyle);
1718-
_needRecalculateStyle = false;
1719-
}
1720-
17211712
void recalculateStyle({bool rebuildNested = false, bool forceRecalculate = false}) {
17221713
if (renderBoxModel != null || forceRecalculate || renderStyle.display == CSSDisplay.none) {
17231714
if (enableWebFProfileTracking) {

webf/lib/src/launcher/controller.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -656,18 +656,6 @@ class WebFViewController implements WidgetsBindingObserver {
656656
}
657657
}
658658

659-
void recalculateStyle(int address) {
660-
if (!hasBindingObject(Pointer.fromAddress(address))) return;
661-
Node? target = getBindingObject<Node>(Pointer.fromAddress(address));
662-
if (target == null) return;
663-
664-
if (target is Element) {
665-
target.tryRecalculateStyle();
666-
} else {
667-
debugPrint('Only element has style, try recalculateStyle from Node(#${Pointer.fromAddress(address)}).');
668-
}
669-
}
670-
671659
// Hooks for DevTools.
672660
VoidCallback? debugDOMTreeChanged;
673661

0 commit comments

Comments
 (0)