-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Add a section about the principle behind React Compiler #8073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Size changes📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me take a stab at this - see my comment on your original PR for more, but purity is actually a small piece of the puzzle for how the compiler works. If we could just rely on functions being pure, the compiler would have a been much simpler.
Yea I hear you. I think it still makes sense as a higher-level explanation for the "big idea" since the rest is about finding boundaries of which things are actually pure. JSX is an obvious such boundary but you can get more granular (and that's what most of the work in the Compiler is actually about). |
My higher-level point is we probably shouldn't let the implementation challenges (and empathy for the work that went into it) obscure the big idea. The big idea absolutely relies on some pieces of code being safe to reorder and/or to "replay" with their outputs. The rest is about how to make that work in JS. I think it's the kind of simplification that is slightly wrong, but if you know why it's wrong, you're already not the target audience because you understand the nuance it skipped. Whereas if you don't know why it's "wrong", this simplification is more truthful than your initial understanding (which is that this is a bunch of adhoc magic). Maybe there's some way to skip to the end and convey a fully accurate picture right away though. |
Maybe:
|
Hmm. I think about it as: React depends on ideas from functional programming. Components and hooks must already be written as pure for the programming model to work and retain local reasoning (it’s only safe to mutate props, hook args, or hook return values if you can make assumptions about how they’ll be used, which breaks composition). The compiler just builds on this idea to help bound the mutability. I’d like to get this point across in some form, and build the intuition around how we decide what to memoize. We also don’t do reordering (yet). |
How about:
|
Since it does change the execution flow with skipping, I sort of think about it as reordering. Though I see it's not exactly the same. I think it helps build the intuition though if you start with a stronger guarantee. |
updated with new wording. alternatively, #8074 is a revert |
I think it's good to say this explicitly. Lifted it from #8071.
Also driveby style nit