perf(ivy): avoid first template pass checks during view creation (#32120)

PR Close #32120
This commit is contained in:
Pawel Kozlowski 2019-08-13 15:45:13 +02:00 committed by Andrew Kushnir
parent 964d72610f
commit 4c3b791ff3
5 changed files with 20 additions and 38 deletions

View File

@ -11,14 +11,14 @@ import {attachPatchData} from '../context_discovery';
import {executePreOrderHooks, registerPostOrderHooks} from '../hooks'; import {executePreOrderHooks, registerPostOrderHooks} from '../hooks';
import {ACTIVE_INDEX, CONTAINER_HEADER_OFFSET, LContainer} from '../interfaces/container'; import {ACTIVE_INDEX, CONTAINER_HEADER_OFFSET, LContainer} from '../interfaces/container';
import {ComponentTemplate} from '../interfaces/definition'; import {ComponentTemplate} from '../interfaces/definition';
import {LocalRefExtractor, TAttributes, TContainerNode, TNode, TNodeType} from '../interfaces/node'; import {LocalRefExtractor, TAttributes, TContainerNode, TNode, TNodeType, TViewNode} from '../interfaces/node';
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view'; import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
import {assertNodeType} from '../node_assert'; import {assertNodeType} from '../node_assert';
import {appendChild, removeView} from '../node_manipulation'; import {appendChild, removeView} from '../node_manipulation';
import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state'; import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {getNativeByTNode, load} from '../util/view_utils'; import {getNativeByTNode, load} from '../util/view_utils';
import {addToViewTree, createDirectivesAndLocals, createLContainer, createTView, getOrCreateTNode, resolveDirectives} from './shared'; import {addToViewTree, createDirectivesAndLocals, createLContainer, createTNode, createTView, getOrCreateTNode, resolveDirectives} from './shared';
@ -78,6 +78,10 @@ export function ɵɵtemplate(
const embeddedTView = tContainerNode.tViews = createTView( const embeddedTView = tContainerNode.tViews = createTView(
-1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, -1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null,
tView.schemas); tView.schemas);
const embeddedTViewNode = createTNode(tView, null, TNodeType.View, -1, null, null) as TViewNode;
embeddedTViewNode.injectorIndex = tContainerNode.injectorIndex;
embeddedTView.node = embeddedTViewNode;
if (tView.queries !== null) { if (tView.queries !== null) {
tView.queries.template(tView, tContainerNode); tView.queries.template(tView, tContainerNode);
embeddedTView.queries = tView.queries.embeddedTView(tContainerNode); embeddedTView.queries = tView.queries.embeddedTView(tContainerNode);

View File

@ -304,24 +304,6 @@ export function allocExpando(view: LView, numSlotsToAlloc: number) {
//// Render //// Render
////////////////////////// //////////////////////////
/**
* Used for creating the LView of a dynamic embedded view, either through
* ViewContainerRef.createEmbeddedView() or TemplateRef.createEmbeddedView().
*/
export function createEmbeddedViewAndNode<T>(
tView: TView, context: T, declarationView: LView, injectorIndex: number): LView {
const lView = createLView(declarationView, tView, context, LViewFlags.CheckAlways, null, null);
lView[DECLARATION_VIEW] = declarationView;
assignTViewNodeToLView(tView, null, -1, lView);
if (tView.firstTemplatePass) {
tView.node !.injectorIndex = injectorIndex;
}
return lView;
}
/** /**
* Processes a view in the creation mode. This includes a number of steps in a specific order: * Processes a view in the creation mode. This includes a number of steps in a specific order:
* - creating view query functions (if any); * - creating view query functions (if any);

View File

@ -106,11 +106,14 @@ export function getNativeByTNode(tNode: TNode, lView: LView): RNode {
* @param lView * @param lView
*/ */
export function getNativeByTNodeOrNull(tNode: TNode, lView: LView): RNode|null { export function getNativeByTNodeOrNull(tNode: TNode, lView: LView): RNode|null {
ngDevMode && assertTNodeForLView(tNode, lView);
const index = tNode.index; const index = tNode.index;
const node: RNode|null = index == -1 ? null : unwrapRNode(lView[index]); if (index !== -1) {
ngDevMode && node !== null && assertDomNode(node); ngDevMode && assertTNodeForLView(tNode, lView);
return node; const node: RNode|null = unwrapRNode(lView[index]);
ngDevMode && node !== null && assertDomNode(node);
return node;
}
return null;
} }

View File

@ -17,16 +17,15 @@ import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_Vie
import {Renderer2} from '../render/api'; import {Renderer2} from '../render/api';
import {addToArray, removeFromArray} from '../util/array_utils'; import {addToArray, removeFromArray} from '../util/array_utils';
import {assertDefined, assertGreaterThan, assertLessThan} from '../util/assert'; import {assertDefined, assertGreaterThan, assertLessThan} from '../util/assert';
import {assertLContainer} from './assert'; import {assertLContainer} from './assert';
import {NodeInjector, getParentInjectorLocation} from './di'; import {NodeInjector, getParentInjectorLocation} from './di';
import {addToViewTree, createEmbeddedViewAndNode, createLContainer, renderView} from './instructions/shared'; import {addToViewTree, createLContainer, createLView, renderView} from './instructions/shared';
import {ACTIVE_INDEX, CONTAINER_HEADER_OFFSET, LContainer, VIEW_REFS} from './interfaces/container'; import {ACTIVE_INDEX, CONTAINER_HEADER_OFFSET, LContainer, VIEW_REFS} from './interfaces/container';
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node'; import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node';
import {RComment, RElement, isProceduralRenderer} from './interfaces/renderer'; import {RComment, RElement, isProceduralRenderer} from './interfaces/renderer';
import {isComponent, isLContainer, isLView, isRootView} from './interfaces/type_checks'; import {isComponent, isLContainer, isLView, isRootView} from './interfaces/type_checks';
import {CONTEXT, DECLARATION_LCONTAINER, LView, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view'; import {CONTEXT, DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view';
import {assertNodeOfPossibleTypes} from './node_assert'; import {assertNodeOfPossibleTypes} from './node_assert';
import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation'; import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation';
import {getParentInjectorTNode} from './node_util'; import {getParentInjectorTNode} from './node_util';
@ -108,9 +107,9 @@ export function createTemplateRef<T>(
createEmbeddedView(context: T): viewEngine_EmbeddedViewRef<T> { createEmbeddedView(context: T): viewEngine_EmbeddedViewRef<T> {
const embeddedTView = this._declarationTContainer.tViews as TView; const embeddedTView = this._declarationTContainer.tViews as TView;
const lView = createEmbeddedViewAndNode( const lView = createLView(
embeddedTView, context, this._declarationView, this._declarationView, embeddedTView, context, LViewFlags.CheckAlways, null,
this._declarationTContainer.injectorIndex); embeddedTView.node);
const declarationLContainer = this._declarationView[this._declarationTContainer.index]; const declarationLContainer = this._declarationView[this._declarationTContainer.index];
ngDevMode && assertLContainer(declarationLContainer); ngDevMode && assertLContainer(declarationLContainer);

View File

@ -470,9 +470,6 @@
{ {
"name": "assertTemplate" "name": "assertTemplate"
}, },
{
"name": "assignTViewNodeToLView"
},
{ {
"name": "attachPatchData" "name": "attachPatchData"
}, },
@ -536,9 +533,6 @@
{ {
"name": "createElementRef" "name": "createElementRef"
}, },
{
"name": "createEmbeddedViewAndNode"
},
{ {
"name": "createLContainer" "name": "createLContainer"
}, },