Skip to content

Commit

Permalink
perf(ivy): move attributes array into component def
Browse files Browse the repository at this point in the history
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({
  attrs: [['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.
  • Loading branch information
crisbeto committed Sep 21, 2019
1 parent 04ddcfe commit b90be9e
Show file tree
Hide file tree
Showing 37 changed files with 688 additions and 660 deletions.
160 changes: 97 additions & 63 deletions packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts

Large diffs are not rendered by default.

Expand Up @@ -74,11 +74,11 @@ describe('compiler compliance: bindings', () => {
};

const template = `
const $e0_attrs$ = [${AttributeMarker.Bindings}, "title"];
attrs: [[${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);
Expand Down Expand Up @@ -108,11 +108,11 @@ describe('compiler compliance: bindings', () => {
};

const template = `
const $e0_attrs$ = [${AttributeMarker.Bindings}, "title"];
attrs: [[${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, "");
Expand Down Expand Up @@ -162,13 +162,13 @@ describe('compiler compliance: bindings', () => {
};

const template = `
const $c0$ = [${AttributeMarker.Bindings}, "for"];
attrs: [[${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);
Expand Down Expand Up @@ -640,7 +640,7 @@ describe('compiler compliance: bindings', () => {
};

const template = `
const $e0_attrs$ = ["target", "_blank", "aria-label", "link", ${AttributeMarker.Bindings}, "title", "id", "customEvent"];
attrs: [["target", "_blank", "aria-label", "link", ${AttributeMarker.Bindings}, "title", "id", "customEvent"]],
`;
const result = compile(files, angularFiles);
Expand Down Expand Up @@ -1251,12 +1251,12 @@ describe('compiler compliance: bindings', () => {
`);

const template = `
const $_c0$ = ["id", "my-id"];
const $_c1$ = ["myRef", ""];
attrs: [["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 }}!");
Expand Down Expand Up @@ -1284,13 +1284,13 @@ describe('compiler compliance: bindings', () => {
`);

const template = `
const $_c0$ = ["value", "one", "#myInput", ""];
attrs: [["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();
Expand All @@ -1308,13 +1308,13 @@ describe('compiler compliance: bindings', () => {
`);

const template = `
const $_c0$ = ["[id]", "my-id", "(click)", "onclick"];
attrs: [["[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();
}
Expand Down

0 comments on commit b90be9e

Please sign in to comment.