Skip to content

Commit d63a63a

Browse files
committed
Update on "compiler: Log metrics on pruned memo blocks/values"
Adds additional information to the CompileSuccess LoggerEvent: * `prunedMemoBlocks` is the number of reactive scopes that were pruned for some reason. * `prunedMemoValues` is the number of unique _values_ produced by those scopes. Both numbers exclude blocks that are just a hook call - ie although we create and prune a scope for eg `useState()`, that's just an artifact of the sequencing of our pipeline. So what this metric is counting is cases of _other_ values that go unmemoized. See the new fixture, which takes advantage of improvements in the snap runner to optionally emit the logger events in the .expect.md file if you include the "logger" pragma in a fixture. [ghstack-poisoned]
1 parent 37f6465 commit d63a63a

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/log-pruned-memoization.expect.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,33 @@ import { useState } from "react";
77
import { identity, makeObject_Primitives, useHook } from "shared-runtime";
88

99
function Component() {
10+
// The scopes for x and x2 are interleaved, so this is one scope with two values
1011
const x = makeObject_Primitives();
1112
const x2 = makeObject_Primitives();
1213
useState(null);
1314
identity(x);
1415
identity(x2);
1516

17+
// We create a scope for all call expressions, but prune those with hook calls
18+
// in this case it's _just_ a hook call, so we don't count this as pruned
1619
const y = useHook();
1720

1821
const z = [];
19-
2022
for (let i = 0; i < 10; i++) {
23+
// The scope for obj is pruned bc it's in a loop
2124
const obj = makeObject_Primitives();
2225
z.push(obj);
2326
}
2427

28+
// Overall we expect two pruned scopes (for x+x2, and obj), with 3 pruned scope values.
2529
return [x, x2, y, z];
2630
}
2731

32+
export const FIXTURE_ENTRYPOINT = {
33+
fn: Component,
34+
params: [{}],
35+
};
36+
2837
```
2938

3039
## Code
@@ -36,6 +45,7 @@ import { identity, makeObject_Primitives, useHook } from "shared-runtime";
3645

3746
function Component() {
3847
const $ = _c(5);
48+
3949
const x = makeObject_Primitives();
4050
const x2 = makeObject_Primitives();
4151
useState(null);
@@ -67,13 +77,18 @@ function Component() {
6777
return t0;
6878
}
6979

80+
export const FIXTURE_ENTRYPOINT = {
81+
fn: Component,
82+
params: [{}],
83+
};
84+
7085
```
7186

7287
## Logs
7388

7489
```
75-
{"kind":"CompileSuccess","fnLoc":{"start":{"line":5,"column":0,"index":121},"end":{"line":22,"column":1,"index":431},"filename":"log-pruned-memoization.ts"},"fnName":"Component","memoSlots":5,"memoBlocks":2,"prunedMemoBlocks":2,"prunedMemoValues":3}
90+
{"kind":"CompileSuccess","fnLoc":{"start":{"line":5,"column":0,"index":121},"end":{"line":26,"column":1,"index":813},"filename":"log-pruned-memoization.ts"},"fnName":"Component","memoSlots":5,"memoBlocks":2,"prunedMemoBlocks":2,"prunedMemoValues":3}
7691
```
7792
7893
### Eval output
79-
(kind: exception) Fixture not implemented
94+
(kind: ok) [{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},[{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true}]]

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/log-pruned-memoization.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@ import { useState } from "react";
33
import { identity, makeObject_Primitives, useHook } from "shared-runtime";
44

55
function Component() {
6+
// The scopes for x and x2 are interleaved, so this is one scope with two values
67
const x = makeObject_Primitives();
78
const x2 = makeObject_Primitives();
89
useState(null);
910
identity(x);
1011
identity(x2);
1112

13+
// We create a scope for all call expressions, but prune those with hook calls
14+
// in this case it's _just_ a hook call, so we don't count this as pruned
1215
const y = useHook();
1316

1417
const z = [];
15-
1618
for (let i = 0; i < 10; i++) {
19+
// The scope for obj is pruned bc it's in a loop
1720
const obj = makeObject_Primitives();
1821
z.push(obj);
1922
}
2023

24+
// Overall we expect two pruned scopes (for x+x2, and obj), with 3 pruned scope values.
2125
return [x, x2, y, z];
2226
}
27+
28+
export const FIXTURE_ENTRYPOINT = {
29+
fn: Component,
30+
params: [{}],
31+
};

0 commit comments

Comments
 (0)