Skip to content
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

feat: optimize performance for recalculate styles. #579

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: optimize recalculate style.
  • Loading branch information
andycall committed Apr 7, 2024
commit fd649183eb12e761bd0c5b1de30dac13e31cab30
11 changes: 0 additions & 11 deletions webf/lib/src/bridge/ui_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ List<UICommand> nativeUICommandToDart(List<int> rawMemory, int commandLength, do

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

for(UICommand command in commands) {
UICommandType commandType = command.type;
Expand Down Expand Up @@ -268,7 +267,6 @@ void execUICommands(WebFViewController view, List<UICommand> commands) {
String key = nativeStringToString(nativeKey);
freeNativeString(nativeKey);
view.setAttribute(nativePtr.cast<NativeBindingObject>(), key, command.args);
pendingRecalculateTargets.add(nativePtr.address);
if (enableWebFProfileTracking) {
WebFProfiler.instance.finishTrackUICommandStep();
}
Expand Down Expand Up @@ -343,15 +341,6 @@ void execUICommands(WebFViewController view, List<UICommand> commands) {
WebFProfiler.instance.startTrackUICommandStep('FlushUICommand.recalculateStyle');
}

for (var address in pendingRecalculateTargets) {
try {
view.recalculateStyle(address);
} catch (e, stack) {
print('$e\n$stack');
}
}
pendingRecalculateTargets.clear();

if (enableWebFProfileTracking) {
WebFProfiler.instance.finishTrackUICommandStep();
}
Expand Down
11 changes: 1 addition & 10 deletions webf/lib/src/dom/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin
updateRenderBoxModel();
}

bool _needRecalculateStyle = false;

final ElementRuleCollector _elementRuleCollector = ElementRuleCollector();

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

@mustCallSuper
void setAttribute(String qualifiedName, String value) {
internalSetAttribute(qualifiedName, value);
ElementAttributeProperty? propertyHandler = _attributeProperties[qualifiedName];
if (propertyHandler != null && propertyHandler.setter != null) {
propertyHandler.setter!(value);
}
final isNeedRecalculate = _checkRecalculateStyle([qualifiedName]);
_needRecalculateStyle = _needRecalculateStyle || isNeedRecalculate;
internalSetAttribute(qualifiedName, value);
}

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

void tryRecalculateStyle({bool rebuildNested = false}) {
recalculateStyle(forceRecalculate: _needRecalculateStyle);
_needRecalculateStyle = false;
}

void recalculateStyle({bool rebuildNested = false, bool forceRecalculate = false}) {
if (renderBoxModel != null || forceRecalculate || renderStyle.display == CSSDisplay.none) {
if (enableWebFProfileTracking) {
Expand Down
12 changes: 0 additions & 12 deletions webf/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -656,18 +656,6 @@ class WebFViewController implements WidgetsBindingObserver {
}
}

void recalculateStyle(int address) {
if (!hasBindingObject(Pointer.fromAddress(address))) return;
Node? target = getBindingObject<Node>(Pointer.fromAddress(address));
if (target == null) return;

if (target is Element) {
target.tryRecalculateStyle();
} else {
debugPrint('Only element has style, try recalculateStyle from Node(#${Pointer.fromAddress(address)}).');
}
}

// Hooks for DevTools.
VoidCallback? debugDOMTreeChanged;

Expand Down
Loading