Skip to content

Commit e557dbb

Browse files
committedJun 21, 2024·
Update on "[compiler] Optimize emission in normal (non-value) blocks"
In #29863 I tried to find a clean way to share code for emitting instructions between value blocks and regular blocks. The catch is that value blocks have special meaning for their final instruction — that's the value of the block — so reordering can't change the last instruction. However, in finding a clean way to share code for these two categories of code, i also inadvertently reduced the effectiveness of the optimization. This PR updates to use different strategies for these two kinds of blocks: value blocks use the code from #29863 where we first emit all non-reorderable instructions in their original order, _then_ try to emit reorderable values. The reason this is suboptimal, though, is that we want to move instructions closer to their dependencies so that they can invalidate (merge) together. Emitting the reorderable values last prevents this. So for normal blocks, we now emit terminal operands first. This will invariably cause _some_ of the non-reorderable instructions to be emitted, but it will intersperse reoderable instructions in between, right after their dependencies. This maximizes our ability to merge scopes. I think the complexity cost of two strategies is worth the benefit, though i still need to double-check all the output changes. [ghstack-poisoned]
2 parents a9e95fa + 469ce8f commit e557dbb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
 

‎compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ref-like-name-in-effect.expect.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,29 @@ function useCustomRef() {
4747

4848
function Foo() {
4949
const $ = _c(3);
50-
const ref = useCustomRef();
5150
let t0;
52-
let t1;
5351
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
54-
t0 = () => {
55-
ref.current?.click();
56-
};
57-
t1 = [];
52+
t0 = <div>foo</div>;
5853
$[0] = t0;
59-
$[1] = t1;
6054
} else {
6155
t0 = $[0];
62-
t1 = $[1];
6356
}
64-
useEffect(t0, t1);
57+
const ref = useCustomRef();
58+
let t1;
6559
let t2;
66-
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
67-
t2 = <div>foo</div>;
60+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
61+
t1 = () => {
62+
ref.current?.click();
63+
};
64+
t2 = [];
65+
$[1] = t1;
6866
$[2] = t2;
6967
} else {
68+
t1 = $[1];
7069
t2 = $[2];
7170
}
72-
return t2;
71+
useEffect(t1, t2);
72+
return t0;
7373
}
7474

7575
export const FIXTURE_ENTRYPOINT = {

0 commit comments

Comments
 (0)
Please sign in to comment.