Repository navigation
[No QA] Add CI check for calls that lose React Compiler caching - #106100
roryabraham merged 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. |
A function that only cached callbacks or objects on main and stops compiling was skipped, because the old rule required a guarded call. Count cache guards instead, so cases like useColumnResize in Expensify#105128 are flagged.
|
@bernhardoj Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c213b053d1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…ith their own extension Optional-chained calls and new expressions are separate Babel node types, so moving one out of a cache guard went unreported. A file renamed between .ts and .tsx compiled main with the new extension, which failed on JSX and silently skipped the comparison.
|
Hi is there any update with this pr ? @roryabraham @bernhardoj |
|
Sorry, I missed this. I'll review this tomorrow |
|
For the 4th step, I also see |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
Hi thanks I fixed it in the pr body |
ok I added it to the pr body |
| visit(node.consequent, {...context, isGuarded: true}, nameHint); | ||
| } | ||
| if (BabelASTUtils.isASTNode(node.alternate)) { | ||
| visit(node.alternate, context, nameHint); |
There was a problem hiding this comment.
Just realized, do we need to visit the alternate branch? It adds nothing to the function call as far as I understand.
There was a problem hiding this comment.
you right , I removed this else :)
roryabraham
left a comment
There was a problem hiding this comment.
For context, I'm not 100% sure that we'll need to keep this particular solution forever (I have some fledgling ideas about how it might be obviated by a new lint rule and/or upstream React Compiler improvements). In the meantime, this seems like it will be a good way to prevent performance regressions.
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.5.36-0 🚀
|
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.5.36-0 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
#104522 removed manual memoization from compiled code. Every changed file still compiled, so the React Compiler compliance check passed, but many components and hooks lost their caching and ran heavy work on every render. This PR adds a third rule to
react-compiler-compliance-check check-changedthat catches this.How it works: for every modified .ts/.tsx file that exists on main (new files, tests and files the compiler skips are left out), the check compiles the main version and the branch version with the same React Compiler config the build uses. In each compiled function it counts every call as guarded, meaning it sits inside an
ifthat reads the compiler cache$[...], or unguarded, meaning it runs on every render. Calls inside callbacks, hook calls and compiler helpers are ignored. JSX elements count as<Name>, and compiler temporaries are normalized so renumbering does not cause noise. A call is reported when its guarded count drops and its unguarded count rises, so a new uncached call next to cached ones is not reported. A function that cached something on main and is no longer compiled on the branch is reported as "no longer compiled". The failure names the function and the callee that now runs on every render.contributingGuides/REACT_COMPILER.mddescribes the rule and how to fix a failure.Validation: run on the #104522 merge, the check flags 93 of the 919 modified files in about 19 seconds, including every file we later had to fix (
useReportActionsPagination,useReportPreviewSenderID,TransactionPreviewContent,MoneyRequestReceiptView,SearchAutocompleteList,SearchSelectionFooterand others). So #104522 would have failed this check.Costs:
.github/workflows/react-compiler-compliance.ymlalready runscheck-changedon every PR that touches .ts/.tsx files, and rule 3 runs inside that step.TransactionListItemInnerand [Rules Engine Release 2] [App] Support expense defaults for more than just merchants #104155 inuseTaxAmount) are worth fixing. The other three ([Insights polish] Update pie chart labels styling and total value formatting #105747, [CP Staging] fix: restore Connections tab param scoping and the accounting help link #105735, [Payment due @FitseTLT] [NoQA] Remove the globalReimbursementFX beta #105659) lose caching on cheap calls, so about 2% of PRs would be blocked for little gain.Known gaps:
End-to-end validation: I ran
npm run react-compiler-compliance-check check-changed --remote upstreamlocally on upstream/main 7b9f88e with this PR applied.src/hooks/useReportActionsPagination.ts: fails, listingisConciergeChatReport,getFilteredReportActionsForReportView,isReportTransactionThreadUtil,allReportActions.at,isCreatedAction,isMoneyRequestReport,isInvoiceReport,getReportPreviewReportAction,getReportActionsToDisplay,getCombinedReportActions,allReportActions.map,t.mapas "now runs on every render".isOfflinetoisNetworkOfflineand add a comment in the same hook): pass.This run used the local merge-base path. In CI the check gets the changed files from the GitHub files API and compares against origin/main, but both paths feed the same rule-3 code.
Fixed Issues
$ #106004
PROPOSAL:
Tests
src/hooks/useReportActionsPagination.tspart of [Perf] Restore React Compiler caching in useReportActionsPagination #105781 (merge commit 63eeabb), for example withgit diff 63eeabb9b75 63eeabb9b75^1 -- src/hooks/useReportActionsPagination.ts | git apply. No commit is needed.npm run react-compiler-compliance-check check-changed --remote upstream(use the name of your Expensify/App remote).useReportActionsPagination, and lists these calls as running on every render:isConciergeChatReport,getFilteredReportActionsForReportView,isReportTransactionThreadUtil,allReportActions.at,isCreatedAction,isMoneyRequestReport,isInvoiceReport,getReportPreviewReportAction,getReportActionsToDisplay,getCombinedReportActions,allReportActions.map,t.map.git checkout -- src/hooks/useReportActionsPagination.ts.Offline tests
N/A, CI script only.
QA Steps
None, CI script only.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari