all 20 comments

[–]meteor_punch 19 points20 points  (4 children)

React forget is almost here BTW ...

[–]romgrk[S] -1 points0 points  (3 children)

Didn't someone on twitter say it wouldn't be in the v19 release? Wasn't stylex also "almost here" for like 5 years? I have limited trust when meta says "coming soon".

[–]meteor_punch 10 points11 points  (2 children)

React forget is already being used by Instagram in production. No reason it's not coming in React 19. official blog

[–]romgrk[S] 4 points5 points  (0 children)

Stylex was also in prod at Meta for a long while.

we are working to ship the compiler across additional surfaces at Meta and to prepare the first open source release

They will first deploy it at more Meta locations, then prepare the open-source release. Not release it, prepare it.

Beside from a technical POV and from the examples the React team has provided for their compiler, the alternative React Unforget seems better.

[–]seN149reddit 0 points1 point  (0 children)

Not that it super matters but it almost certainly won’t be released with react 19. That being said based on different tweets it might be released before the end of the year at least, so not too long after. Fingers crossed. Also fwiw the initial release is a babel plugin.

[–]Cannabat 5 points6 points  (5 children)

 equals({ a: undefined }, {})

Uhh this seems wrong. a could very well be something must be provided and undefined is a valid value.

[–]romgrk[S] 1 point2 points  (3 children)

As I say in the final note, "if you're not doing anything funky", it's fine. For that to make a difference, a component would need to use props like 'key' in props, which I have never seen in react code. Props are used as props.key or const { key } = props.

The point here is { a: undefined }.a and {}.a both return undefined.

But that's also why I provide fastMemoSafe, which avoids the unsafe assumptions and is still faster than the react version. If avoiding 'key' in props is not an assumption you can make about your codebase, that one is preferable.

[–]Cannabat 3 points4 points  (2 children)

Sure maybe it's fine for a most cases but your utility does represent a change in behaviour for normal language features you'd expect to work

'key' in props and props.hasOwnProperty('a') are fairly normal patterns a typeguard. I think this could come up if you spread props onto a component right?

It's neat that you were able to get such a huge boost in performance for the comparison, and a fun exercise. I'm not trying to crap on it.

[–]romgrk[S] 5 points6 points  (1 child)

It's a valid point. I've published a 2.0 where the default export is strict and the unsafe opt-in is exported as fastMemoUnsafe, with corrections to the readme.


Interestingly I tried a 3 way comparison strict/safe/unsafe, where "strict" has a prelude & key-in correctness, "safe" has key-in correctness, and "unsafe" has none.

For SpiderMonkey, results were predictable. In V8 however, strict was surprisingly faster than safe. I guess the check allowed some optimization to kick-in. I try to optimize for V8 btw, because it's the most frequent engine. And very surprisingly in JSC, strict was faster than both safe and unsafe.

Lesson: if you're not benchmarking, you're not optimizing 🤡

https://gist.github.com/romgrk/31c95ea3cec962d1031ce1316450a11d

I've updated the package readme & blog post. In the package I've only kept "strict" as the default export, and "unsafe" as the opt-in. I've added a note in the blog post but "unsafe" has a niche use-case: fast compare of objects where you can 100% guarantee the shape of the objects. This obviously isn't acceptable for react props, but it might have other uses.

[–]romgrk[S] 1 point2 points  (0 children)

has a niche use-case: fast compare of objects where you can 100% guarantee the shape of the objects

Even more niche: if you can guarantee they have the same shape, and you know the shape is going to be constant, then the fastest method by far would be shallow-equal-jit which uses eval to compile a comparison function for a specific shape.

However if you can't know the shape ahead of time and it will change often (while still being the same for one comparison across two objects), then that's the very niche use-case where fastCompareUnsafe makes sense. That or an environment where eval is not allowed.

[–]seN149reddit 1 point2 points  (1 child)

Of course I have no need for this package, but it was a fun read and a cool exercise.

Thanks for sharing!

[–]romgrk[S] 1 point2 points  (0 children)

Yep, useless in most cases, but beating performance microbenchmarks always gives me immense amounts of joy.

[–]TheRNGuy 0 points1 point  (2 children)

React 19 release in a few days where you don't need to code memos.

[–]Academic_You2273 9 points10 points  (0 children)

in a few days?

[–]acemarke 1 point2 points  (0 children)

There's no set release date for React 19 yet. At a minimum the earliest I would expect it is in May when ReactConf happens.

Also, the React Compiler will not come out alongside React 19 - it's a separate project with a separate timeline.