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

[BACKPORT] Performance Tuning for Ember 3.13 #963

Merged
Merged
Changes from 2 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
34 changes: 22 additions & 12 deletions packages/@glimmer/reference/lib/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,27 @@ function _combine(tags: Tag[]): Tag {
export abstract class CachedTag extends RevisionTag {
private lastChecked: Option<Revision> = null;
private lastValue: Option<Revision> = null;
private isUpdating = false;

value(): Revision {
let { lastChecked } = this;

if (lastChecked !== $REVISION) {
this.isUpdating = true;
this.lastChecked = $REVISION;
this.lastValue = this.compute();

try {
this.lastValue = this.compute();
} finally {
this.isUpdating = false;
}
}

return this.lastValue as Revision;
}
if (this.isUpdating) {
this.lastChecked = ++$REVISION;
}

protected invalidate() {
this.lastChecked = null;
return this.lastValue as Revision;
}

protected abstract compute(): Revision;
Expand Down Expand Up @@ -244,30 +251,33 @@ class TagsCombinator extends CachedTag {
register(TagsCombinator);

export class UpdatableTag extends CachedTag {
static create(tag: Tag): TagWrapper<UpdatableTag> {
static create(tag: Tag = CONSTANT_TAG): TagWrapper<UpdatableTag> {
return new TagWrapper(this.id, new UpdatableTag(tag));
}

private tag: Tag;
private lastUpdated: number;
private revision: Revision;

private constructor(tag: Tag) {
private constructor(tag: Tag, revision = $REVISION) {
super();
this.tag = tag;
this.lastUpdated = INITIAL;
this.revision = revision;
}

protected compute(): Revision {
return Math.max(this.lastUpdated, this.tag.value());
return Math.max(this.tag.value(), this.revision);
}

update(tag: Tag) {
if (tag !== this.tag) {
this.tag = tag;
this.lastUpdated = $REVISION;
this.invalidate();
++$REVISION;
}
}

dirty() {
this.revision = ++$REVISION;
}
}

register(UpdatableTag);
Expand Down