Skip to content

Commit

Permalink
perf(core): generate arrow functions for pure function calls (#51668)
Browse files Browse the repository at this point in the history
Reworks the pure functions to use arrow functions with an implicit return instead of function expressions. This allows us to shave off some bytes for each pure function, because we can avoid some of the syntax.

PR Close #51668
  • Loading branch information
crisbeto authored and thePunderWoman committed Sep 6, 2023
1 parent 8ad21cc commit 88a0af6
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 29 deletions.
@@ -1,6 +1,6 @@
const $c0$ = function () { return { foo: null }; };
const $c1$ = function () { return []; };
const $c2$ = function (a0) { return { foo: a0 }; };
const $c0$ = () => ({ foo: null });
const $c1$ = () => [];
const $c2$ = a0 => ({ foo: a0 });
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,5 +1,5 @@
const $c0$ = function () { return []; };
const $c1$ = function () { return [0, 1, 2]; };
const $c0$ = () => [];
const $c1$ = () => [0, 1, 2];
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,5 +1,5 @@
const $c0$ = function () { return {}; };
const $c1$ = function () { return { a: 1, b: 2 }; };
const $c0$ = () => ({});
const $c1$ = () => ({ a: 1, b: 2 });
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,6 +1,6 @@
const $c0$ = function () { return { foo: null }; };
const $c1$ = function () { return {}; };
const $c2$ = function (a0) { return { foo: a0 }; };
const $c0$ = () => ({ foo: null });
const $c1$ = () => ({});
const $c2$ = a0 => ({ foo: a0 });
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,5 +1,5 @@
const $c0$ = function () { return { foo: null }; };
const $c1$ = function (a0) { return { foo: a0 }; };
const $c0$ = () => ({ foo: null });
const $c1$ = a0 => ({ foo: a0 });
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,6 +1,4 @@
const $c0$ = function ($a0$) {
return [$a0$, 1, 2, 3, 4, 5];
};
const $c0$ = $a0$ => [$a0$, 1, 2, 3, 4, 5];
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,4 +1,4 @@
const $e0_ff$ = function ($v$) { return ["Nancy", $v$]; };
const $e0_ff$ = $v$ => ["Nancy", $v$];
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,6 +1,4 @@
const $e0_ff$ = function ($v0$, $v1$, $v2$, $v3$, $v4$, $v5$, $v6$, $v7$, $v8$) {
return ["start-", $v0$, $v1$, $v2$, $v3$, $v4$, "-middle-", $v5$, $v6$, $v7$, $v8$, "-end"];
}
const $e0_ff$ = ($v0$, $v1$, $v2$, $v3$, $v4$, $v5$, $v6$, $v7$, $v8$) => ["start-", $v0$, $v1$, $v2$, $v3$, $v4$, "-middle-", $v5$, $v6$, $v7$, $v8$, "-end"];
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,7 +1,7 @@
const $c0$ = function () { return {opacity: 0, duration: 0}; };
const $e0_ff$ = function ($v$) { return {opacity: 1, duration: $v$}; };
const $e0_ff_1$ = function ($v1$, $v2$) { return [$v1$, $v2$]; };
const $e0_ff_2$ = function ($v1$, $v2$) { return {animation: $v1$, actions: $v2$}; };
const $c0$ = () => ({opacity: 0, duration: 0});
const $e0_ff$ = $v$ => ({opacity: 1, duration: $v$});
const $e0_ff_1$ = ($v1$, $v2$) => [$v1$, $v2$];
const $e0_ff_2$ = ($v1$, $v2$) => ({animation: $v1$, actions: $v2$});
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,4 +1,4 @@
const $e0_ff$ = function ($v$) { return {"duration": 500, animation: $v$}; };
const $e0_ff$ = $v$ => ({"duration": 500, animation: $v$});
// ...
MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: MyApp,
Expand Down
@@ -1,6 +1,6 @@
const $_c0$ = function (a0, a1) { return { collapsedHeight: a0, expandedHeight: a1 }; };
const $_c1$ = function (a0, a1) { return { value: a0, params: a1 }; };
const $_c2$ = function (a0, a1) { return { collapsedWidth: a0, expandedWidth: a1 }; };
const $_c0$ = (a0, a1) => ({ collapsedHeight: a0, expandedHeight: a1 });
const $_c1$ = (a0, a1) => ({ value: a0, params: a1 });
const $_c2$ = (a0, a1) => ({ collapsedWidth: a0, expandedWidth: a1 });
hostVars: 14,
hostBindings: function MyComponent_HostBindings(rf, ctx) {
Expand Down
@@ -1,5 +1,5 @@

const $ff$ = function ($v$) { return ["red", $v$]; };
const $ff$ = $v$ => ["red", $v$];
HostBindingComp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: HostBindingComp,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/constant_pool.ts
Expand Up @@ -222,7 +222,7 @@ export class ConstantPool {
const parameters =
resultExpressions.filter(isVariable).map(e => new o.FnParam(e.name!, o.DYNAMIC_TYPE));
const pureFunctionDeclaration =
o.fn(parameters, [new o.ReturnStatement(resultMap(resultExpressions))], o.INFERRED_TYPE);
o.arrowFn(parameters, resultMap(resultExpressions), o.INFERRED_TYPE);
const name = this.freshName();
this.statements.push(o.variable(name)
.set(pureFunctionDeclaration)
Expand Down

0 comments on commit 88a0af6

Please sign in to comment.