Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion integration/_payload-limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"master": {
"uncompressed": {
"runtime-es2015": 1485,
"main-es2015": 14861,
"main-es2015": 15039,
"polyfills-es2015": 36808
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/render3/PERF_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,24 @@ Here is an example of code which breaks the inlining and a way to fix it.
```
export function i18nStart(index: number, message: string, subTemplateIndex?: number): void {
const tView = getTView();
if (tView.firstTemplatePass && tView.data[index + HEADER_OFFSET] === null) {
if (tView.firstCreatePass && tView.data[index + HEADER_OFFSET] === null) {
// LOTS OF CODE HERE WHICH PREVENTS INLINING.
}
}
```

Notice that the above function almost never runs because `tView.firstTemplatePass` is usually false.
Notice that the above function almost never runs because `tView.firstCreatePass` is usually false.
The application would benefit from inlining, but the large code inside `if` prevents it.
Simple refactoring will fix it.

```
export function i18nStart(index: number, message: string, subTemplateIndex?: number): void {
const tView = getTView();
if (tView.firstTemplatePass && tView.data[index + HEADER_OFFSET] === null) {
i18nStartFirstTemplatePass(tView, index, message, subTemplateIndex)
if (tView.firstCreatePass && tView.data[index + HEADER_OFFSET] === null) {
i18nStartfirstCreatePass(tView, index, message, subTemplateIndex)
}
}
export function i18nStartFirstTemplatePass(tView: TView, index: number, message: string, subTemplateIndex?: number): void {
export function i18nStartfirstCreatePass(tView: TView, index: number, message: string, subTemplateIndex?: number): void {
// LOTS OF CODE HERE WHICH PREVENTS INLINING.
}
```
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function assertLView(value: any) {
assertEqual(isLView(value), true, 'Expecting LView');
}

export function assertFirstTemplatePass(tView: TView, errMessage?: string) {
export function assertFirstCreatePass(tView: TView, errMessage?: string) {
assertEqual(
tView.firstTemplatePass, true, errMessage || 'Should only be called in first template pass.');
tView.firstCreatePass, true, errMessage || 'Should only be called in first create pass.');
}
6 changes: 3 additions & 3 deletions packages/core/src/render3/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function createRootComponentView(
rootView, getOrCreateTView(def), null, def.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways,
rootView[HEADER_OFFSET], tNode, rendererFactory, renderer, sanitizer);

if (tView.firstTemplatePass) {
if (tView.firstCreatePass) {
diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, rootView), tView, def.type);
markAsComponentHost(tView, tNode);
initNodeFlags(tNode, rootView.length, 1);
Expand Down Expand Up @@ -209,14 +209,14 @@ export function createRootComponent<T>(
}

const rootTNode = getPreviousOrParentTNode();
if (tView.firstTemplatePass && componentDef.hostBindings) {
if (tView.firstCreatePass && componentDef.hostBindings) {
const elementIndex = rootTNode.index - HEADER_OFFSET;
setActiveHostElement(elementIndex);
incrementActiveDirectiveId();

const expando = tView.expandoInstructions !;
invokeHostBindingsInCreationMode(
componentDef, expando, component, rootTNode, tView.firstTemplatePass);
componentDef, expando, component, rootTNode, tView.firstCreatePass);

setActiveHostElement(null);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ let nextNgElementId = 0;
*/
export function bloomAdd(
injectorIndex: number, tView: TView, type: Type<any>| InjectionToken<any>| string): void {
ngDevMode && assertEqual(tView.firstTemplatePass, true, 'expected firstTemplatePass to be true');
ngDevMode && assertEqual(tView.firstCreatePass, true, 'expected firstCreatePass to be true');
let id: number|undefined =
typeof type !== 'string' ? (type as any)[NG_ELEMENT_ID] : type.charCodeAt(0) || 0;

Expand Down Expand Up @@ -147,7 +147,7 @@ export function getOrCreateNodeInjectorForNode(
}

const tView = hostView[TVIEW];
if (tView.firstTemplatePass) {
if (tView.firstCreatePass) {
tNode.injectorIndex = hostView.length;
insertBloom(tView.data, tNode); // foundation for node bloom
insertBloom(hostView, null); // foundation for cumulative bloom
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/di_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function providersResolver<T>(
def: DirectiveDef<T>, providers: Provider[], viewProviders: Provider[]): void {
const lView = getLView();
const tView: TView = lView[TVIEW];
if (tView.firstTemplatePass) {
if (tView.firstCreatePass) {
const isComponent = isComponentDef(def);

// The list of view providers is processed first, and the flags are updated
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/render3/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {assertEqual, assertNotEqual} from '../util/assert';

import {assertFirstTemplatePass} from './assert';
import {assertFirstCreatePass} from './assert';
import {DirectiveDef} from './interfaces/definition';
import {TNode} from './interfaces/node';
import {FLAGS, HookData, InitPhaseState, LView, LViewFlags, PREORDER_HOOK_FLAGS, PreOrderHookFlags, TView} from './interfaces/view';
Expand Down Expand Up @@ -36,7 +36,7 @@ import {getCheckNoChangesMode} from './state';
export function registerPreOrderHooks(
directiveIndex: number, directiveDef: DirectiveDef<any>, tView: TView, nodeIndex: number,
initialPreOrderHooksLength: number, initialPreOrderCheckHooksLength: number): void {
ngDevMode && assertFirstTemplatePass(tView);
ngDevMode && assertFirstCreatePass(tView);
const {onChanges, onInit, doCheck} = directiveDef;
if (initialPreOrderHooksLength >= 0 &&
(!tView.preOrderHooks || initialPreOrderHooksLength === tView.preOrderHooks.length) &&
Expand Down Expand Up @@ -85,7 +85,7 @@ export function registerPreOrderHooks(
* @param tNode The TNode whose directives are to be searched for hooks to queue
*/
export function registerPostOrderHooks(tView: TView, tNode: TNode): void {
ngDevMode && assertFirstTemplatePass(tView);
ngDevMode && assertFirstCreatePass(tView);
// It's necessary to loop through the directives at elementEnd() (rather than processing in
// directiveCreate) so we can preserve the current hook order. Content, view, and destroy
// hooks for projected components and directives must be called *before* their hosts.
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/render3/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export function ɵɵi18nStart(index: number, message: string, subTemplateIndex?:
i18nIndexStack[++i18nIndexStackPointer] = index;
// We need to delay projections until `i18nEnd`
setDelayProjection(true);
if (tView.firstTemplatePass && tView.data[index + HEADER_OFFSET] === null) {
if (tView.firstCreatePass && tView.data[index + HEADER_OFFSET] === null) {
i18nStartFirstPass(lView, tView, index, message, subTemplateIndex);
}
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ function i18nAttributesFirstPass(lView: LView, tView: TView, index: number, valu
// Even indexes are text (including bindings)
const hasBinding = !!value.match(BINDING_REGEXP);
if (hasBinding) {
if (tView.firstTemplatePass && tView.data[index + HEADER_OFFSET] === null) {
if (tView.firstCreatePass && tView.data[index + HEADER_OFFSET] === null) {
addAllToArray(
generateBindingUpdateOpCodes(value, previousElementIndex, attrName), updateOpCodes);
}
Expand All @@ -1027,7 +1027,7 @@ function i18nAttributesFirstPass(lView: LView, tView: TView, index: number, valu
}
}

if (tView.firstTemplatePass && tView.data[index + HEADER_OFFSET] === null) {
if (tView.firstCreatePass && tView.data[index + HEADER_OFFSET] === null) {
tView.data[index + HEADER_OFFSET] = updateOpCodes;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/render3/instructions/alloc_host_vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {NO_CHANGE} from '../tokens';
export function ɵɵallocHostVars(count: number): void {
const lView = getLView();
const tView = lView[TVIEW];
if (!tView.firstTemplatePass) return;
if (!tView.firstCreatePass) return;
queueHostBindingForCheck(tView, getCurrentDirectiveDef() !, count);
prefillHostVars(tView, lView, count);
}
Expand All @@ -34,7 +34,7 @@ export function ɵɵallocHostVars(count: number): void {
function queueHostBindingForCheck(
tView: TView, def: DirectiveDef<any>| ComponentDef<any>, hostVars: number): void {
ngDevMode &&
assertEqual(tView.firstTemplatePass, true, 'Should only be called in first template pass.');
assertEqual(tView.firstCreatePass, true, 'Should only be called in first create pass.');
const expando = tView.expandoInstructions !;
const length = expando.length;
// Check whether a given `hostBindings` function already exists in expandoInstructions,
Expand All @@ -56,7 +56,7 @@ function queueHostBindingForCheck(
*/
function prefillHostVars(tView: TView, lView: LView, totalHostVars: number): void {
ngDevMode &&
assertEqual(tView.firstTemplatePass, true, 'Should only be called in first template pass.');
assertEqual(tView.firstCreatePass, true, 'Should only be called in first create pass.');
for (let i = 0; i < totalHostVars; i++) {
lView.push(NO_CHANGE);
tView.blueprint.push(NO_CHANGE);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/render3/instructions/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function ɵɵcontainer(index: number): void {
const lView = getLView();
const tNode = containerInternal(lView, index, null, null);

if (lView[TVIEW].firstTemplatePass) {
if (lView[TVIEW].firstCreatePass) {
tNode.tViews = [];
}
setIsNotParent();
Expand Down Expand Up @@ -75,8 +75,8 @@ export function ɵɵtemplate(
const tContainerNode = containerInternal(
lView, index, tagName || null, getConstant(tViewConsts, attrsIndex) as TAttributes);
const localRefs = getConstant(tViewConsts, localRefsIndex) as string[];
if (tView.firstTemplatePass) {
ngDevMode && ngDevMode.firstTemplatePass++;
if (tView.firstCreatePass) {
ngDevMode && ngDevMode.firstCreatePass++;
resolveDirectives(tView, lView, tContainerNode, localRefs);
registerPostOrderHooks(tView, tContainerNode);

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/render3/instructions/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function ɵɵelementStart(

if (attrs != null) {
const lastAttrIndex = setUpAttributes(renderer, native, attrs);
if (tView.firstTemplatePass) {
if (tView.firstCreatePass) {
registerInitialStylingOnTNode(tNode, attrs, lastAttrIndex);
}
}
Expand All @@ -82,8 +82,8 @@ export function ɵɵelementStart(
// flow through that (except for `[class.prop]` bindings). This also includes initial
// static class values as well. (Note that this will be fixed once map-based `[style]`
// and `[class]` bindings work for multiple directives.)
if (tView.firstTemplatePass) {
ngDevMode && ngDevMode.firstTemplatePass++;
if (tView.firstCreatePass) {
ngDevMode && ngDevMode.firstCreatePass++;
const hasDirectives = resolveDirectives(tView, lView, tNode, localRefs);
ngDevMode && validateElement(lView, native, tNode, hasDirectives);

Expand Down Expand Up @@ -125,7 +125,7 @@ export function ɵɵelementEnd(): void {

decreaseElementDepthCount();

if (tView.firstTemplatePass) {
if (tView.firstCreatePass) {
registerPostOrderHooks(tView, previousOrParentTNode);
if (isContentQueryHost(previousOrParentTNode)) {
tView.queries !.elementEnd(previousOrParentTNode);
Expand Down Expand Up @@ -210,7 +210,7 @@ export function ɵɵelementHostAttrs(attrs: TAttributes) {
if (tNode.type === TNodeType.Element) {
const native = getNativeByTNode(tNode, lView) as RElement;
const lastAttrIndex = setUpAttributes(lView[RENDERER], native, attrs);
if (tView.firstTemplatePass) {
if (tView.firstCreatePass) {
const stylingNeedsToBeRendered = registerInitialStylingOnTNode(tNode, attrs, lastAttrIndex);

// this is only called during the first template pass in the
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/render3/instructions/element_container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function ɵɵelementContainerStart(
const tNode =
getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.ElementContainer, tagName, attrs);

if (attrs && tView.firstTemplatePass) {
if (attrs && tView.firstCreatePass) {
// While ng-container doesn't necessarily support styling, we use the style context to identify
// and execute directives on the ng-container.
registerInitialStylingOnTNode(tNode, attrs, 0);
Expand All @@ -66,8 +66,8 @@ export function ɵɵelementContainerStart(
appendChild(native, tNode, lView);
attachPatchData(native, lView);

if (tView.firstTemplatePass) {
ngDevMode && ngDevMode.firstTemplatePass++;
if (tView.firstCreatePass) {
ngDevMode && ngDevMode.firstCreatePass++;
resolveDirectives(tView, lView, tNode, localRefs);
if (tView.queries) {
tView.queries.elementStart(tView, tNode);
Expand Down Expand Up @@ -103,7 +103,7 @@ export function ɵɵelementContainerEnd(): void {

ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.ElementContainer);

if (tView.firstTemplatePass) {
if (tView.firstCreatePass) {
registerPostOrderHooks(tView, previousOrParentTNode);
if (isContentQueryHost(previousOrParentTNode)) {
tView.queries !.elementEnd(previousOrParentTNode);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ function listenerInternal(
eventTargetResolver?: GlobalTargetResolver): void {
const tView = lView[TVIEW];
const isTNodeDirectiveHost = isDirectiveHost(tNode);
const firstTemplatePass = tView.firstTemplatePass;
const tCleanup: false|any[] = firstTemplatePass && (tView.cleanup || (tView.cleanup = []));
const firstCreatePass = tView.firstCreatePass;
const tCleanup: false|any[] = firstCreatePass && (tView.cleanup || (tView.cleanup = []));

ngDevMode && assertNodeOfPossibleTypes(
tNode, TNodeType.Element, TNodeType.Container, TNodeType.ElementContainer);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/render3/instructions/lview_debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export const TViewConstructor = class TView implements ITView {
public bindingStartIndex: number, //
public expandoStartIndex: number, //
public expandoInstructions: ExpandoInstructions|null, //
public firstTemplatePass: boolean, //
public firstCreatePass: boolean, //
public firstUpdatePass: boolean, //
public staticViewQueries: boolean, //
public staticContentQueries: boolean, //
public preOrderHooks: HookData|null, //
Expand Down
Loading