-
Notifications
You must be signed in to change notification settings - Fork 6.8k
perf(table) Coalesces style updates after style measurements to reduc… #19750
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
jelbourn
merged 18 commits into
angular:master
from
kseamon:table-coalesce-measurements
Jul 27, 2020
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0289fd3
perf(table) Coalesces style updates after style measurements to reduc…
kseamon b79c2b7
Add license
kseamon 1161834
Fix column resize tests
kseamon a050e41
Fixed mdc-table tests
kseamon c386bdc
jsdoc
kseamon 68f7eae
more comments
kseamon b2c05b3
lint
kseamon af10e1f
lint
kseamon 45d8565
Added _
kseamon 48d6bf5
lint
kseamon 06dd6b2
-override
kseamon 498ff4c
update api
kseamon 1c6064e
prevent resource leaks
kseamon 3f25d3c
api
kseamon 42478d4
readonly
kseamon ae4ab43
remove changes that are part of #19739
kseamon 0685b57
Change to onStable to work around downstream test failures
kseamon ad091c3
api update
kseamon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Injectable, NgZone, OnDestroy} from '@angular/core'; | ||
import {Subject} from 'rxjs'; | ||
import {take, takeUntil} from 'rxjs/operators'; | ||
|
||
/** | ||
* @docs-private | ||
*/ | ||
export class _Schedule { | ||
tasks: (() => unknown)[] = []; | ||
endTasks: (() => unknown)[] = []; | ||
} | ||
|
||
/** | ||
* Allows grouping up CSSDom mutations after the current execution context. | ||
* This can significantly improve performance when separate consecutive functions are | ||
* reading from the CSSDom and then mutating it. | ||
* | ||
* @docs-private | ||
*/ | ||
@Injectable() | ||
export class _CoalescedStyleScheduler implements OnDestroy { | ||
private _currentSchedule: _Schedule|null = null; | ||
private readonly _destroyed = new Subject<void>(); | ||
|
||
constructor(private readonly _ngZone: NgZone) {} | ||
|
||
/** | ||
* Schedules the specified task to run at the end of the current VM turn. | ||
*/ | ||
schedule(task: () => unknown): void { | ||
this._createScheduleIfNeeded(); | ||
|
||
this._currentSchedule!.tasks.push(task); | ||
} | ||
|
||
/** | ||
* Schedules the specified task to run after other scheduled tasks at the end of the current | ||
* VM turn. | ||
*/ | ||
scheduleEnd(task: () => unknown): void { | ||
this._createScheduleIfNeeded(); | ||
|
||
this._currentSchedule!.endTasks.push(task); | ||
} | ||
|
||
/** Prevent any further tasks from running. */ | ||
ngOnDestroy() { | ||
this._destroyed.next(); | ||
this._destroyed.complete(); | ||
} | ||
|
||
private _createScheduleIfNeeded() { | ||
if (this._currentSchedule) { return; } | ||
|
||
this._currentSchedule = new _Schedule(); | ||
|
||
this._ngZone.onStable.pipe( | ||
take(1), | ||
takeUntil(this._destroyed), | ||
).subscribe(() => { | ||
const schedule = this._currentSchedule!; | ||
this._currentSchedule = null; | ||
|
||
for (const task of schedule.tasks) { | ||
task(); | ||
} | ||
for (const task of schedule.endTasks) { | ||
task(); | ||
} | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.