-
Notifications
You must be signed in to change notification settings - Fork 47.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler][patch] Patch O(n^2) traversal in validatePreserveMemo
Double checked by syncing internally and verifying the # of `visitInstruction` calls with unique `InstructionId`s. This is a bit of an awkward pattern though. A cleaner alternative might be to override `visitValue` and store its results in a sidemap (instead of returning) ghstack-source-id: f6797d765224fb49c7d26cd377319662830d7348 Pull Request resolved: #30077
- Loading branch information
Showing
4 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ler/src/__tests__/fixtures/compiler/repro-slow-validate-preserve-memo.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @validatePreserveExistingMemoizationGuarantees | ||
|
||
import { Builder } from "shared-runtime"; | ||
function useTest({ isNull, data }: { isNull: boolean; data: string }) { | ||
const result = Builder.makeBuilder(isNull, "hello world") | ||
?.push("1", 2) | ||
?.push(3, { | ||
a: 4, | ||
b: 5, | ||
c: data, | ||
}) | ||
?.push(6, data) | ||
?.push(7, "8") | ||
?.push("8", Builder.makeBuilder(!isNull)?.push(9).vals)?.vals; | ||
return result; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useTest, | ||
params: [{ isNull: false, data: "param" }], | ||
}; | ||
|
||
``` | ||
## Code | ||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees | ||
|
||
import { Builder } from "shared-runtime"; | ||
function useTest(t0) { | ||
const $ = _c(3); | ||
const { isNull, data } = t0; | ||
let t1; | ||
if ($[0] !== isNull || $[1] !== data) { | ||
t1 = Builder.makeBuilder(isNull, "hello world") | ||
?.push("1", 2) | ||
?.push(3, { a: 4, b: 5, c: data }) | ||
?.push( | ||
6, | ||
|
||
data, | ||
) | ||
?.push(7, "8") | ||
?.push("8", Builder.makeBuilder(!isNull)?.push(9).vals)?.vals; | ||
$[0] = isNull; | ||
$[1] = data; | ||
$[2] = t1; | ||
} else { | ||
t1 = $[2]; | ||
} | ||
const result = t1; | ||
return result; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useTest, | ||
params: [{ isNull: false, data: "param" }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) ["hello world","1",2,3,{"a":4,"b":5,"c":"param"},6,"param",7,"8","8",null] |
21 changes: 21 additions & 0 deletions
21
...lugin-react-compiler/src/__tests__/fixtures/compiler/repro-slow-validate-preserve-memo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @validatePreserveExistingMemoizationGuarantees | ||
|
||
import { Builder } from "shared-runtime"; | ||
function useTest({ isNull, data }: { isNull: boolean; data: string }) { | ||
const result = Builder.makeBuilder(isNull, "hello world") | ||
?.push("1", 2) | ||
?.push(3, { | ||
a: 4, | ||
b: 5, | ||
c: data, | ||
}) | ||
?.push(6, data) | ||
?.push(7, "8") | ||
?.push("8", Builder.makeBuilder(!isNull)?.push(9).vals)?.vals; | ||
return result; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useTest, | ||
params: [{ isNull: false, data: "param" }], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters