Skip to content

Commit

Permalink
[FEATURE] Tracked Props Performance Tuning (#18223)
Browse files Browse the repository at this point in the history
[FEATURE] Tracked Props Performance Tuning
  • Loading branch information
rwjblue authored Aug 14, 2019
2 parents 5c72325 + 5bbd43e commit e971418
Show file tree
Hide file tree
Showing 32 changed files with 484 additions and 445 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
"@babel/plugin-transform-shorthand-properties": "^7.2.0",
"@babel/plugin-transform-spread": "^7.2.2",
"@babel/plugin-transform-template-literals": "^7.4.4",
"@glimmer/compiler": "0.38.5-alpha.1",
"@glimmer/compiler": "0.38.5-alpha.2",
"@glimmer/env": "^0.1.7",
"@glimmer/interfaces": "0.38.5-alpha.1",
"@glimmer/node": "0.38.5-alpha.1",
"@glimmer/opcode-compiler": "0.38.5-alpha.1",
"@glimmer/program": "0.38.5-alpha.1",
"@glimmer/reference": "0.38.5-alpha.1",
"@glimmer/runtime": "0.38.5-alpha.1",
"@glimmer/interfaces": "0.38.5-alpha.2",
"@glimmer/node": "0.38.5-alpha.2",
"@glimmer/opcode-compiler": "0.38.5-alpha.2",
"@glimmer/program": "0.38.5-alpha.2",
"@glimmer/reference": "0.38.5-alpha.2",
"@glimmer/runtime": "0.38.5-alpha.2",
"@types/qunit": "^2.5.4",
"@types/rsvp": "^4.0.2",
"auto-dist-tag": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Simple,
VMHandle,
} from '@glimmer/interfaces';
import { combine, Tag, VersionedPathReference } from '@glimmer/reference';
import { combine, Tag, validate, value, VersionedPathReference } from '@glimmer/reference';
import {
Arguments,
Bounds,
Expand Down Expand Up @@ -414,10 +414,10 @@ export default class CurlyComponentManager

bucket.finalizer = _instrumentStart('render.component', rerenderInstrumentDetails, component);

if (args && !args.tag.validate(argsRevision)) {
if (args && !validate(args.tag, argsRevision)) {
let props = processComponentArgs(args!);

bucket.argsRevision = args!.tag.value();
bucket.argsRevision = value(args!.tag);

component[IS_DISPATCHING_ATTRS] = true;
component.setProperties(props);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEBUG } from '@glimmer/env';
import { ComponentCapabilities } from '@glimmer/interfaces';
import { CONSTANT_TAG, Tag, VersionedPathReference } from '@glimmer/reference';
import { CONSTANT_TAG, Tag, validate, value, VersionedPathReference } from '@glimmer/reference';
import { ComponentDefinition, Invocation, WithDynamicLayout } from '@glimmer/runtime';
import { Destroyable, Opaque, Option } from '@glimmer/util';

Expand Down Expand Up @@ -96,7 +96,7 @@ class MountManager
bucket = { engine, controller, self, tag };
} else {
let model = modelRef.value();
let modelRev = modelRef.tag.value();
let modelRev = value(modelRef.tag);
controller = controllerFactory.create({ model });
self = new RootReference(controller);
tag = modelRef.tag;
Expand Down Expand Up @@ -126,9 +126,9 @@ class MountManager

update(bucket: EngineWithModelState): void {
let { controller, modelRef, modelRev } = bucket;
if (!modelRef.tag.validate(modelRev!)) {
if (!validate(modelRef.tag, modelRev!)) {
let model = modelRef.value();
bucket.modelRev = modelRef.tag.value();
bucket.modelRev = value(modelRef.tag);
controller.set('model', model);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@ember/-internals/views';
import { assert, deprecate } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { DirtyableTag } from '@glimmer/reference';
import { createTag, dirty } from '@glimmer/reference';
import { normalizeProperty, SVG_NAMESPACE } from '@glimmer/runtime';

import { RootReference, UPDATE } from './utils/references';
Expand Down Expand Up @@ -721,7 +721,7 @@ const Component = CoreView.extend(
init() {
this._super(...arguments);
this[IS_DISPATCHING_ATTRS] = false;
this[DIRTY_TAG] = DirtyableTag.create();
this[DIRTY_TAG] = createTag();
this[ROOT_REF] = new RootReference(this);
this[BOUNDS] = null;

Expand Down Expand Up @@ -776,7 +776,7 @@ const Component = CoreView.extend(
},

rerender() {
this[DIRTY_TAG].inner.dirty();
dirty(this[DIRTY_TAG]);
this._super();
},

Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FrameworkObject, setFrameworkClass } from '@ember/-internals/runtime';
import { symbol } from '@ember/-internals/utils';
import { join } from '@ember/runloop';
import { Dict, Opaque } from '@glimmer/interfaces';
import { DirtyableTag } from '@glimmer/reference';
import { createTag, dirty } from '@glimmer/reference';

export const RECOMPUTE_TAG = symbol('RECOMPUTE_TAG');

Expand Down Expand Up @@ -85,7 +85,7 @@ export function isSimpleHelper(helper: SimpleHelper | HelperInstance): helper is
let Helper = FrameworkObject.extend({
init() {
this._super(...arguments);
this[RECOMPUTE_TAG] = DirtyableTag.create();
this[RECOMPUTE_TAG] = createTag();
},

/**
Expand Down Expand Up @@ -116,7 +116,7 @@ let Helper = FrameworkObject.extend({
@since 1.13.0
*/
recompute() {
join(() => this[RECOMPUTE_TAG].inner.dirty());
join(() => dirty(this[RECOMPUTE_TAG]));
},

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/@ember/-internals/glimmer/lib/helpers/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { set } from '@ember/-internals/metal';
import { Opaque } from '@glimmer/interfaces';
import {
combine,
CONSTANT_TAG,
createUpdatableTag,
isConst,
PathReference,
Tag,
TagWrapper,
UpdatableTag,
update,
VersionedPathReference,
} from '@glimmer/reference';
import { Arguments, NULL_REFERENCE, VM } from '@glimmer/runtime';
Expand Down Expand Up @@ -85,7 +85,7 @@ class GetHelperReference extends CachedReference {
public pathReference: PathReference<string>;
public lastPath: string | null;
public innerReference: VersionedPathReference<Opaque>;
public innerTag: TagWrapper<UpdatableTag>;
public innerTag: UpdatableTag;
public tag: Tag;

static create(
Expand All @@ -111,7 +111,7 @@ class GetHelperReference extends CachedReference {
this.lastPath = null;
this.innerReference = NULL_REFERENCE;

let innerTag = (this.innerTag = UpdatableTag.create(CONSTANT_TAG));
let innerTag = (this.innerTag = createUpdatableTag());

this.tag = combine([sourceReference.tag, pathReference.tag, innerTag]);
}
Expand All @@ -122,7 +122,7 @@ class GetHelperReference extends CachedReference {

if (path !== lastPath) {
innerReference = referenceFromPath(this.sourceReference, path);
innerTag.inner.update(innerReference.tag);
update(innerTag, innerReference.tag);
this.innerReference = innerReference;
this.lastPath = path;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@ember/-internals/glimmer/lib/helpers/if-unless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*/

import { assert } from '@ember/debug';
import { combine, CONSTANT_TAG, isConst, TagWrapper, UpdatableTag } from '@glimmer/reference';
import { combine, createUpdatableTag, isConst, UpdatableTag, update } from '@glimmer/reference';
import { Arguments, PrimitiveReference, VM } from '@glimmer/runtime';
import { CachedReference, ConditionalReference } from '../utils/references';

class ConditionalHelperReference extends CachedReference {
public branchTag: TagWrapper<UpdatableTag>;
public branchTag: UpdatableTag;
public tag: any;
public cond: any;
public truthy: any;
Expand All @@ -30,7 +30,7 @@ class ConditionalHelperReference extends CachedReference {
constructor(cond: any, truthy: any, falsy: any) {
super();

this.branchTag = UpdatableTag.create(CONSTANT_TAG);
this.branchTag = createUpdatableTag();
this.tag = combine([cond.tag, this.branchTag]);

this.cond = cond;
Expand All @@ -41,7 +41,7 @@ class ConditionalHelperReference extends CachedReference {
compute() {
let branch = this.cond.value() ? this.truthy : this.falsy;

this.branchTag.inner.update(branch.tag);
update(this.branchTag, branch.tag);

return branch.value();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/modifiers/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { assert, deprecate } from '@ember/debug';
import { flaggedInstrument } from '@ember/instrumentation';
import { join } from '@ember/runloop';
import { Opaque, Simple } from '@glimmer/interfaces';
import { RevisionTag, TagWrapper } from '@glimmer/reference';
import { Tag } from '@glimmer/reference';
import {
Arguments,
CapturedNamedArguments,
Expand Down Expand Up @@ -70,7 +70,7 @@ export class ActionState {
public implicitTarget: any;
public dom: any;
public eventName: any;
public tag: TagWrapper<RevisionTag | null>;
public tag: Tag;

constructor(
element: Simple.Element,
Expand All @@ -81,7 +81,7 @@ export class ActionState {
positionalArgs: CapturedPositionalArguments,
implicitTarget: any,
dom: any,
tag: TagWrapper<RevisionTag | null>
tag: Tag
) {
this.element = element;
this.actionId = actionId;
Expand Down
8 changes: 4 additions & 4 deletions packages/@ember/-internals/glimmer/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getViewElement, getViewId } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { backburner, getCurrentRunLoop } from '@ember/runloop';
import { Option, Simple } from '@glimmer/interfaces';
import { CURRENT_TAG, VersionedPathReference } from '@glimmer/reference';
import { CURRENT_TAG, validate, value, VersionedPathReference } from '@glimmer/reference';
import {
clientBuilder,
CurriedComponentDefinition,
Expand Down Expand Up @@ -431,7 +431,7 @@ export abstract class Renderer {
globalShouldReflush = globalShouldReflush || shouldReflush;
}

this._lastRevision = CURRENT_TAG.value();
this._lastRevision = value(CURRENT_TAG);
} finally {
env.commit();
}
Expand Down Expand Up @@ -467,7 +467,7 @@ export abstract class Renderer {
completedWithoutError = true;
} finally {
if (!completedWithoutError) {
this._lastRevision = CURRENT_TAG.value();
this._lastRevision = value(CURRENT_TAG);
if (this._env.inTransaction === true) {
this._env.commit();
}
Expand Down Expand Up @@ -498,7 +498,7 @@ export abstract class Renderer {
}

_isValid() {
return this._destroyed || this._roots.length === 0 || CURRENT_TAG.validate(this._lastRevision);
return this._destroyed || this._roots.length === 0 || validate(CURRENT_TAG, this._lastRevision);
}

_revalidate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clearElementView, clearViewElement, getViewElement } from '@ember/-internals/views';
import { Revision, VersionedReference } from '@glimmer/reference';
import { Revision, value, VersionedReference } from '@glimmer/reference';
import { CapturedNamedArguments } from '@glimmer/runtime';
import { Opaque } from '@glimmer/util';
import Environment from '../environment';
Expand Down Expand Up @@ -48,7 +48,7 @@ export default class ComponentStateBucket {
public hasWrappedElement: boolean
) {
this.classRef = null;
this.argsRevision = args === null ? 0 : args.tag.value();
this.argsRevision = args === null ? 0 : value(args.tag);
}

destroy() {
Expand Down
12 changes: 6 additions & 6 deletions packages/@ember/-internals/glimmer/lib/utils/iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { assert } from '@ember/debug';
import {
AbstractIterable,
combine,
CONSTANT_TAG,
createUpdatableTag,
IterationItem,
OpaqueIterator,
Tag,
UpdatableTag,
update,
VersionedReference,
} from '@glimmer/reference';
import { Opaque, Option } from '@glimmer/util';
Expand Down Expand Up @@ -261,7 +261,7 @@ const EMPTY_ITERATOR: OpaqueIterator = {

class EachInIterable implements EmberIterable {
public tag: Tag;
private valueTag = UpdatableTag.create(CONSTANT_TAG);
private valueTag = createUpdatableTag();

constructor(private ref: VersionedReference, private keyPath: string) {
this.tag = combine([ref.tag, this.valueTag]);
Expand All @@ -279,7 +279,7 @@ class EachInIterable implements EmberIterable {
iterable = _contentFor(iterable);
}

valueTag.inner.update(tag);
update(valueTag, tag);

if (!isIndexable(iterable)) {
return EMPTY_ITERATOR;
Expand Down Expand Up @@ -331,7 +331,7 @@ class EachInIterable implements EmberIterable {

class EachIterable implements EmberIterable {
public tag: Tag;
private valueTag = UpdatableTag.create(CONSTANT_TAG);
private valueTag = createUpdatableTag();

constructor(private ref: VersionedReference, private keyPath: string) {
this.tag = combine([ref.tag, this.valueTag]);
Expand All @@ -342,7 +342,7 @@ class EachIterable implements EmberIterable {

let iterable = ref.value();

valueTag.inner.update(tagForProperty(iterable, '[]'));
update(valueTag, tagForProperty(iterable, '[]'));

if (iterable === null || typeof iterable !== 'object') {
return EMPTY_ITERATOR;
Expand Down
13 changes: 10 additions & 3 deletions packages/@ember/-internals/glimmer/lib/utils/outlet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Owner } from '@ember/-internals/owner';
import { Opaque } from '@glimmer/interfaces';
import { combine, DirtyableTag, Reference, Tag, VersionedPathReference } from '@glimmer/reference';
import {
combine,
createTag,
dirty,
Reference,
Tag,
VersionedPathReference,
} from '@glimmer/reference';
import { Factory as TemplateFactory, OwnedTemplate } from '../template';

export interface RenderState {
Expand Down Expand Up @@ -63,7 +70,7 @@ export interface OutletState {
* Represents the root outlet.
*/
export class RootOutletReference implements VersionedPathReference<OutletState> {
tag = DirtyableTag.create();
tag = createTag();

constructor(public outletState: OutletState) {}

Expand All @@ -77,7 +84,7 @@ export class RootOutletReference implements VersionedPathReference<OutletState>

update(state: OutletState) {
this.outletState.outlets.main = state;
this.tag.inner.dirty();
dirty(this.tag);
}
}

Expand Down
Loading

0 comments on commit e971418

Please sign in to comment.