-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: bubble set performance workaround #7208
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
Changes from 2 commits
efbbd03
e99261b
b9770dd
00cec11
4a9ff6f
06a9d4a
8602ed9
40643c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,10 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> { | |
|
|
||
| private bubbleSetOptions: IBubbleSetOptions = {}; | ||
|
|
||
| private shallRunUpdateBubbleSetsPath = false; | ||
|
|
||
| private pendingRunUpdateBubbleSetsPath = false; | ||
|
|
||
| static defaultOptions: Partial<BubbleSetsOptions> = { | ||
| members: [], | ||
| avoidMembers: [], | ||
|
|
@@ -125,6 +129,20 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> { | |
| }; | ||
|
|
||
| private updateBubbleSetsPath = (event: ElementLifeCycleEvent) => { | ||
| if (!this.shallRunUpdateBubbleSetsPath) { | ||
| if (!this.pendingRunUpdateBubbleSetsPath) { | ||
| this.pendingRunUpdateBubbleSetsPath = true; | ||
| setTimeout(() => { | ||
| this.shallRunUpdateBubbleSetsPath = true; | ||
| this.updateBubbleSetsPath(event); | ||
| }); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| this.pendingRunUpdateBubbleSetsPath = false; | ||
| this.shallRunUpdateBubbleSetsPath = false; | ||
|
|
||
| if (!this.shape) return; | ||
| const id = idOf(event.data); | ||
| if (![...this.options.members, ...this.options.avoidMembers].includes(id)) return; | ||
|
Comment on lines
128
to
131
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The deferred execution logic is flawed and can lead to missed updates and memory leaks. The The Refactor this to a simpler and more robust debounce pattern. Check if the event is for a member element upfront, use a single timeout ID to manage the debounced call, and clear the timeout in a private updateBubbleSetsPath = (event: ElementLifeCycleEvent) => {
if (!this.shape) return;
const id = idOf(event.data);
if (![...this.options.members, ...this.options.avoidMembers].includes(id)) return;
if (this.updatePathTimeout) {
clearTimeout(this.updatePathTimeout);
}
this.updatePathTimeout = setTimeout(() => {
if (!this.shape) return;
// The actual update logic, which was previously after the check, should be placed here.
// For example: this.drawBubbleSets();
}, 0);
}; |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export const version = '5.0.47'; | ||
| export const version = '5.0.48'; | ||
hustcc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.