Live data from Hacker News

We memo all the things (2020)

attardi.org

11–20 of 84 posts

Re: We memo all the things (2020)

#11
There's no mention of what I think is the most important point: how is this enforced? If that's with a tool, I think it's great and a sane way to do things. If it's by asking everyone to remember doing it, I think it's a missed opportunity.

It's also interesting to see the age-old functional programming problem: you trade performance for ease of development. I think these days people assume that things like immutable data structures are optimised under the hood. That doesn't seem to be the case with React, as you have to explicitly use a performance trick everywhere.

Their argument that it would be premature optimisation to think about where memo is not needed makes sense, it's an interesting shift of optimisation of the runtime performance vs optimisation of the dev time.

> Using memo and its cousins everywhere is a sane default. It’s like a mask mandate during a coronavirus pandemic. Sure, we could have everybody tested every day and only ask people who are actively contagious to wear a mask. But it’s far cheaper, simpler, and ultimately more effective to ask everybody to wear a mask by default.

That's a good metaphor. It's easier for the people who decide, by shifting the burden on everyone else. I personally get headaches by wearing a mask all the time at work. I think I may get headaches too if I had to remember something like this all the time.

Re: We memo all the things (2020)

#12
post #11

There's no mention of what I think is the most important point: how is this enforced? If that's with a tool, I think it's great and a sane way to do things. If it's by asking everyone to remember doing it, I think it's a missed opportunity. It's also interesting to see the age-old functional programming problem: you trade performance for ease of development. I think these days people assume that things like immutable…

I think it would be easy to create a rule to see if the default export is wrapped in memo, but you could also just have it as a coding standard

Re: We memo all the things (2020)

#13
Kind of makes you wonder why React.memo isn't just the default behaviour.

https://github.com/facebook/react/issues/14463#issuecomment-... suggests it was meant to be the default behaviour, but was scrapped because it would "break backwards compatibility". No source is given for that claim though.

Re: We memo all the things (2020)

#14

I like React a lot and have used it professionally for more than 5 years. First off I mostly haven't needed to memoize any time I can remember in any enterprise (non-SaaS) production or personal apps. But surely CoinBase is at a bigger scale than my apps were/are. But if it's the case that memoizing is such a good thing to do despite the effort (and I'm not debating that in this question), why is React designed in a…

yeah, I was thinking about this too as someone who's not super familiar with React — why isn't memoing the default behavior?

I think that's because everyone needs to debug their React app, but not everyone needs the performance. So you optimise for the most common use case, where you make debugging easier. Memoization is a form of caching, caching is hard. Most backend web frameworks don't come with a cache by default, you add one when you need the performance. It's the same here.

Re: We memo all the things (2020)

#15

This is a great article and I agree with it fully. The argument that a lot of popular React voices have made, "React is fast and it's prematurely optimizing to worry about memoizing things until a profile shows you need it", has never rung true with me. First and foremost, there's a huge time cost to figuring out what those exact spots that need optimization are, and there's also an educational cost with teaching les…

I've always thought of "premature optimisation" as optimising something that's not your "hot path". If there's no clear hot path, everything is the hot path, and small optimisation gains everywhere are the only thing you're going to get. So at this point, it's not premature.

You could also rewrite your code so that there is a clear hot path, but in that case it seems to be React rendering, that's optimised by using memo and avoiding it completely.

Re: We memo all the things (2020)

#16
post #11

There's no mention of what I think is the most important point: how is this enforced? If that's with a tool, I think it's great and a sane way to do things. If it's by asking everyone to remember doing it, I think it's a missed opportunity. It's also interesting to see the age-old functional programming problem: you trade performance for ease of development. I think these days people assume that things like immutable…

I think it would be easy to create a rule to see if the default export is wrapped in memo, but you could also just have it as a coding standard

I wonder if this is the plugin they are using:

https://github.com/steadicat/eslint-plugin-react-memo

Does anyone know of any other eslint plugins that help enforce this?

Re: We memo all the things (2020)

#18
post #11

There's no mention of what I think is the most important point: how is this enforced? If that's with a tool, I think it's great and a sane way to do things. If it's by asking everyone to remember doing it, I think it's a missed opportunity. It's also interesting to see the age-old functional programming problem: you trade performance for ease of development. I think these days people assume that things like immutable…

I think it would be easy to create a rule to see if the default export is wrapped in memo, but you could also just have it as a coding standard

What do you mean by coding standard? My point was that if it's enforced by tool, either as a reminder, or an automatic modification, it's fine, but if it's not, it's annoying.

Re: We memo all the things (2020)

#19

I like React a lot and have used it professionally for more than 5 years. First off I mostly haven't needed to memoize any time I can remember in any enterprise (non-SaaS) production or personal apps. But surely CoinBase is at a bigger scale than my apps were/are. But if it's the case that memoizing is such a good thing to do despite the effort (and I'm not debating that in this question), why is React designed in a…

the only time I find it to be required is when passing in callbacks to custom hooks with props that may change and you'll notice immediately because the callback will continuously run
Post reply on HN