perf(ivy): move local references into consts array (#33129)

Follow-up from #32798. Moves the local references array into the component def's `consts` in order to make it compress better.

Before:
```
const _c0 = ['foo', ''];

SomeComp.ngComponentDef = defineComponent({
  template: function() {
    element(0, 'div', null, _c0);
  }
});
```

After:
```
SomeComp.ngComponentDef = defineComponent({
  consts: [['foo', '']],
  template: function() {
    element(0, 'div', null, 0);
  }
});
```

PR Close #33129
This commit is contained in:
crisbeto
2019-10-29 22:20:25 +01:00
committed by atscott
parent 5437e2da29
commit 66725b7b37
22 changed files with 247 additions and 209 deletions

View File

@ -10,7 +10,7 @@ import {SchemaMetadata, ViewEncapsulation} from '../../core';
import {ProcessProvidersFunction} from '../../di/interface/provider';
import {Type} from '../../interface/type';
import {TAttributes} from './node';
import {TConstants} from './node';
import {CssSelectorList} from './projection';
import {TView} from './view';
@ -227,7 +227,7 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
readonly template: ComponentTemplate<T>;
/** Constants associated with the component's view. */
readonly consts: TAttributes[]|null;
readonly consts: TConstants|null;
/**
* An array of `ngContent[selector]` values that were found in the template.

View File

@ -224,6 +224,13 @@ export const enum AttributeMarker {
*/
export type TAttributes = (string | AttributeMarker | CssSelector)[];
/**
* Constants that are associated with a view. Includes:
* - Attribute arrays.
* - Local definition arrays.
*/
export type TConstants = (TAttributes | string)[];
/**
* Binding data (flyweight) for a particular node that is shared between all templates
* of a specific type.

View File

@ -15,7 +15,7 @@ import {Sanitizer} from '../../sanitization/sanitizer';
import {LContainer} from './container';
import {ComponentDef, ComponentTemplate, DirectiveDef, DirectiveDefList, HostBindingsFunction, PipeDef, PipeDefList, ViewQueriesFunction} from './definition';
import {I18nUpdateOpCodes, TI18n} from './i18n';
import {TAttributes, TElementNode, TNode, TViewNode} from './node';
import {TAttributes, TConstants, TElementNode, TNode, TViewNode} from './node';
import {PlayerHandler} from './player';
import {LQueries, TQueries} from './query';
import {RElement, Renderer3, RendererFactory3} from './renderer';
@ -555,10 +555,10 @@ export interface TView {
schemas: SchemaMetadata[]|null;
/**
* Array of attributes for all of the elements in the view. Used
* for directive matching and attribute bindings.
* Array of constants for the view. Includes attribute arrays, local definition arrays etc.
* Used for directive matching, attribute bindings, local definitions and more.
*/
consts: TAttributes[]|null;
consts: TConstants|null;
}
export const enum RootContextFlags {Empty = 0b00, DetectChanges = 0b01, FlushPlayers = 0b10}