perf(ivy): move attributes array into component def (#32798)
Currently Ivy stores the element attributes into an array above the component def and passes it into the relevant instructions, however the problem is that upon minification the array will get a unique name which won't compress very well. These changes move the attributes array into the component def and pass in the index into the instructions instead. Before: ``` const _c0 = ['foo', 'bar']; SomeComp.ngComponentDef = defineComponent({ template: function() { element(0, 'div', _c0); } }); ``` After: ``` SomeComp.ngComponentDef = defineComponent({ consts: [['foo', 'bar']], template: function() { element(0, 'div', 0); } }); ``` A couple of cases that this PR doesn't handle: * Template references are still in a separate array. * i18n attributes are still in a separate array. PR Close #32798
This commit is contained in:

committed by
Alex Rickabaugh

parent
b2b917d2d8
commit
d5b87d32b0
@ -74,11 +74,11 @@ describe('compiler compliance: bindings', () => {
|
||||
};
|
||||
|
||||
const template = `
|
||||
const $e0_attrs$ = [${AttributeMarker.Bindings}, "title"];
|
||||
…
|
||||
consts: [[${AttributeMarker.Bindings}, "title"]],
|
||||
template:function MyComponent_Template(rf, $ctx$){
|
||||
if (rf & 1) {
|
||||
$i0$.ɵɵelement(0, "a", $e0_attrs$);
|
||||
$i0$.ɵɵelement(0, "a", 0);
|
||||
}
|
||||
if (rf & 2) {
|
||||
$i0$.ɵɵproperty("title", $ctx$.title);
|
||||
@ -108,11 +108,11 @@ describe('compiler compliance: bindings', () => {
|
||||
};
|
||||
|
||||
const template = `
|
||||
const $e0_attrs$ = [${AttributeMarker.Bindings}, "title"];
|
||||
…
|
||||
consts: [[${AttributeMarker.Bindings}, "title"]],
|
||||
template:function MyComponent_Template(rf, $ctx$){
|
||||
if (rf & 1) {
|
||||
$i0$.ɵɵelement(0, "a", $e0_attrs$);
|
||||
$i0$.ɵɵelement(0, "a", 0);
|
||||
}
|
||||
if (rf & 2) {
|
||||
$i0$.ɵɵpropertyInterpolate1("title", "Hello ", $ctx$.name, "");
|
||||
@ -162,13 +162,13 @@ describe('compiler compliance: bindings', () => {
|
||||
};
|
||||
|
||||
const template = `
|
||||
const $c0$ = [${AttributeMarker.Bindings}, "for"];
|
||||
consts: [[${AttributeMarker.Bindings}, "for"]]
|
||||
|
||||
// ...
|
||||
|
||||
function MyComponent_Template(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$i0$.ɵɵelement(0, "label", _c0);
|
||||
$i0$.ɵɵelement(0, "label", 0);
|
||||
}
|
||||
if (rf & 2) {
|
||||
$i0$.ɵɵproperty("for", ctx.forValue);
|
||||
@ -640,7 +640,7 @@ describe('compiler compliance: bindings', () => {
|
||||
};
|
||||
|
||||
const template = `
|
||||
const $e0_attrs$ = ["target", "_blank", "aria-label", "link", ${AttributeMarker.Bindings}, "title", "id", "customEvent"];
|
||||
consts: [["target", "_blank", "aria-label", "link", ${AttributeMarker.Bindings}, "title", "id", "customEvent"]],
|
||||
…
|
||||
`;
|
||||
const result = compile(files, angularFiles);
|
||||
@ -725,7 +725,7 @@ describe('compiler compliance: bindings', () => {
|
||||
$r3$.ɵɵhostProperty("id", $r3$.ɵɵpureFunction1(1, $ff$, ctx.id));
|
||||
}
|
||||
},
|
||||
consts: 0,
|
||||
decls: 0,
|
||||
vars: 0,
|
||||
template: function HostBindingComp_Template(rf, ctx) {},
|
||||
encapsulation: 2
|
||||
@ -1251,12 +1251,12 @@ describe('compiler compliance: bindings', () => {
|
||||
`);
|
||||
|
||||
const template = `
|
||||
const $_c0$ = ["id", "my-id"];
|
||||
const $_c1$ = ["myRef", ""];
|
||||
…
|
||||
consts: [["id", "my-id"]],
|
||||
template:function MyComponent_Template(rf, $ctx$){
|
||||
if (rf & 1) {
|
||||
$i0$.ɵɵelementStart(0, "b", $_c0$, $_c1$);
|
||||
$i0$.ɵɵelementStart(0, "b", 0, $_c1$);
|
||||
$i0$.ɵɵdisableBindings();
|
||||
$i0$.ɵɵelementStart(2, "i");
|
||||
$i0$.ɵɵtext(3, "Hello {{ name }}!");
|
||||
@ -1284,13 +1284,13 @@ describe('compiler compliance: bindings', () => {
|
||||
`);
|
||||
|
||||
const template = `
|
||||
const $_c0$ = ["value", "one", "#myInput", ""];
|
||||
…
|
||||
consts: [["value", "one", "#myInput", ""]],
|
||||
template:function MyComponent_Template(rf, $ctx$){
|
||||
if (rf & 1) {
|
||||
$i0$.ɵɵelementStart(0, "div");
|
||||
$i0$.ɵɵdisableBindings();
|
||||
$i0$.ɵɵelement(1, "input", $_c0$);
|
||||
$i0$.ɵɵelement(1, "input", 0);
|
||||
$i0$.ɵɵtext(2, " {{ myInput.value }} ");
|
||||
$i0$.ɵɵenableBindings();
|
||||
$i0$.ɵɵelementEnd();
|
||||
@ -1308,13 +1308,13 @@ describe('compiler compliance: bindings', () => {
|
||||
`);
|
||||
|
||||
const template = `
|
||||
const $_c0$ = ["[id]", "my-id", "(click)", "onclick"];
|
||||
…
|
||||
consts: [["[id]", "my-id", "(click)", "onclick"]],
|
||||
template:function MyComponent_Template(rf, $ctx$){
|
||||
if (rf & 1) {
|
||||
$i0$.ɵɵelementStart(0, "div");
|
||||
$i0$.ɵɵdisableBindings();
|
||||
$i0$.ɵɵelement(1, "div", $_c0$);
|
||||
$i0$.ɵɵelement(1, "div", 0);
|
||||
$i0$.ɵɵenableBindings();
|
||||
$i0$.ɵɵelementEnd();
|
||||
}
|
||||
|
Reference in New Issue
Block a user