HybridManager: improve widget disposal#2085
Open
fschinkel wants to merge 1 commit intoreleases/26.2from
Open
Conversation
411586d to
c572753
Compare
Add api to HybridManager.ts for widget disposal. Widgets that need to be disposed are collected and the scout.DisposeWidgets-hybrid action is only called once. In addition, listen for destroyed widgets and send a scout.DisposeWidgets-hybrid action as well. All widgets for which a disposal was scheduled are excluded from property change events in the future as destroyed widgets may no longer be resolved. Improve performance of DisposeWidgetsHybridAction. The HybridManager adds dispose-listeners to all its widgets and removes them from itself when they are disposed. For this the HybridManager needs to build a new map of widgets, each time its "widgets" property is updated. If a great amount of widgets is disposed, each disposal triggers a rebuild of the HybridManagers "widgets" property. The DisposeWidgetsHybridAction will now remove all widgets that are to be disposed from the HybridManager at once and dispose them afterward. With this the "widgets" property of the HybridManager is only updated once which improves performance when great amounts of widgets are disposed. 379008
c572753 to
a8d6765
Compare
cguglielmo
reviewed
Mar 30, 2026
| Object.entries(removedWidgets).forEach(([id, widget]) => this._triggerWidgetRemove(id, widget)); | ||
| Object.entries(addedWidgets).forEach(([id, widget]) => { | ||
| this._installHybridManagerWidget(widget, id); | ||
| // trigger widgetAdd event |
Member
There was a problem hiding this comment.
There is no need to add a comment if the method call is meaningful enough and basically the same as the comment
| } | ||
| // get all widgets that need to be disposed | ||
| Map<String, IWidget> widgets = hybridManager().getWidgets().entrySet().stream() | ||
| .filter(entry -> data.getIds().contains(entry.getKey()) && entry.getValue() != null) |
Member
There was a problem hiding this comment.
Why not loop over data.getIds() and call getWidgetById()? It would be faster because looping over getWidgets() and using getIds().contains is O(n^2)
| // collect remote ids, transfer widget ids to this._disposeWidgetsScheduledWidgetIds and reset next batch | ||
| const remoteIds: string[] = []; | ||
| for (const widget of [...this._disposeWidgetsNextBatch]) { | ||
| remoteIds.push(widget.__remoteId); |
Member
There was a problem hiding this comment.
- widget.__removeId is null for forms, because _uninstallHybridManagerWidget is called before the microtask runs
- Forms are disposed on server, do we even need a destroy listener for forms?
| * Set of ids that were scheduled in former batches. | ||
| * See {@link #_callDisposeWidgets} for more information. | ||
| */ | ||
| protected _disposeWidgetsScheduledWidgetIds = new Set<string>(); |
Member
There was a problem hiding this comment.
the name is a little cumbersome... Maybe call it widgetIdsBeingDisposed and the other one _widgetsToBeDisposed?
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.
Add api to HybridManager.ts for widget disposal. Widgets that need to be disposed are collected and the scout.DisposeWidgets-hybrid action is only called once. In addition, listen for destroyed widgets and send a scout.DisposeWidgets-hybrid action as well.
All widgets for which a disposal was scheduled are excluded from property change events in the future as destroyed widgets may no longer be resolved.
Improve performance of DisposeWidgetsHybridAction. The HybridManager adds dispose-listeners to all its widgets and removes them from itself when they are disposed. For this the HybridManager needs to build a new map of widgets, each time its "widgets" property is updated. If a great amount of widgets is disposed, each disposal triggers a rebuild of the HybridManagers "widgets" property. The DisposeWidgetsHybridAction will now remove all widgets that are to be disposed from the HybridManager at once and dispose them afterward. With this the "widgets" property of the HybridManager is only updated once which improves performance when great amounts of widgets are disposed.
379008