Skip to content

Conversation

gaearon
Copy link
Member

@gaearon gaearon commented Oct 11, 2025

I think it's good to say this explicitly. Lifted it from #8071.

Also driveby style nit

@meta-cla meta-cla bot added the CLA Signed label Oct 11, 2025
@gaearon gaearon marked this pull request as ready for review October 11, 2025 15:51
Copy link

github-actions bot commented Oct 11, 2025

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link
Member

@josephsavona josephsavona left a 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.

@gaearon
Copy link
Member Author

gaearon commented Oct 11, 2025

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).

@gaearon
Copy link
Member Author

gaearon commented Oct 11, 2025

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.

@gaearon
Copy link
Member Author

gaearon commented Oct 11, 2025

Maybe:

Fundamentally, React Compiler relies on an old idea from functional programming: pure functions don't "do" anything (they only compute things), so it is safe to reorder their calls, or to reuse their past output for the same inputs. React Compiler checks that your components follow the Rules of React, and breaks up their code into smaller pieces that can be reused and reordered this way.

@josephsavona
Copy link
Member

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).

@gaearon
Copy link
Member Author

gaearon commented Oct 11, 2025

How about:

You can get an intuitive sense of how the Compiler works by looking at the playground.

Like many features in React itself, React Compiler relies on an old idea from functional programming: pure functions don't "do" anything (they only compute things), so it is safe to reorder their calls, or to reuse their past output for the same inputs. React Compiler verifies that your components follow the Rules of React, and then breaks up their code into smaller pure pieces that can be safely skipped or potentially reordered.

@gaearon
Copy link
Member Author

gaearon commented Oct 11, 2025

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.

@gaearon
Copy link
Member Author

gaearon commented Oct 11, 2025

updated with new wording. alternatively, #8074 is a revert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants