163 points · by ggurgone · 9y ago · 115 comments
[0] https://github.com/markerikson/redux-ecosystem-links/blob/ma... .
[1] https://github.com/markerikson/redux-ecosystem-links
[2] https://github.com/markerikson/react-redux-links/blob/master...
Not only do you get a big performance boost, but your code is greatly improved.
Depends on the size of your data. AFAIK handling immutable data has a performance penalty on smaller datasets. Before I go immutable I first assess whether I really need it.
[0] Vanilla JS immutable types heavily optimize this. Immutable.js does as well, although there's obviously more overhead.
There's a few different reasons why handling data immutably in a React app is a good thing. The main one is that it allows straightforward implementation of `shouldComponentUpdate` by simply doing shallow equality checks against props and state to see if anything has changed. (I wrote a Reddit comment yesterday explaining why that works well, at https://www.reddit.com/r/reactjs/comments/666uin/can_someone... ).
For example, say you have an action that fetches a bunch of blog posts, then refetches later. If all the items are identical since the last fetch, you want to avoid rendering. So that means that whenever you deal with data updates, de-duplication has to occur at some point, preferably early on in the data layer when the surface area is minimal.
That de-duplication would need to "intern" data; i.e. if you fetch the new blog posts, check each of them if they are exactly the same as what's already cached (time stamps or version numbers could be used to save deep equality checks), and keep the existing object if that's the case.
Of course, you will still end up with lots of identical objects (different identity, but same content) purely because mutations generate them. For example, a user goes to a text field, types a character and then hits backspace. Now you've produced three different objects: version 0 (original data), version 1 (character added), version 2 (identical to v0, different identity). This will correctly re-render each version, of course. But let's say you had some other component (like a preview) that only updated every second. It would receive v0, v1, v2; at this point the delta of v2-v0 is zero, and there's no need to re-render; but a shallow equality check would cause it to. So de-duping needs to be built into all sorts of places you might not anticipate.
For alternative re-rendering troubleshooting, read https://medium.com/dailyjs/react-is-slow-react-is-fast-optim...
You have some data (props and state) that defines the current state of your program. This data is passed to a rendering function, which creates a virtual DOM representation of the component based on the data. After this has happened, the virtual DOM is diffed against the previously built virtual DOM to see if we should tell the browser to render the real DOM based on the new virtual one.
So the general cycle works like this:
Data was updated -> virtual render -> diff new virtual DOM vs old virtual DOM -> real render if necessary.
However, both constructing the virtual DOM as well as diffing the DOMs takes considerable amounts of time. That's why React offers a short-cut to avoid it, if necessary: shouldComponentUpdate. This lifecycle method is called after your data updates and before the virtual render takes place, allowing you to short-circuit the process if you already know that your data didn't change in a way that changes the resulting DOM.
So with the short-circuit, there are two general pathways. If you know the data didn't affect the DOM:
Data was updated -> return false in shouldComponentUpdate -> nothing more happens.
If you know the data affects the DOM or you're not sure:
Data was updated -> return true in shouldComponentUpdate -> virtual render -> diff new virtual DOM vs old virtual DOM -> real render if necessary.
The value of the tool is that it monkey-patches some React internals to notify you when you have missed a chance to use shouldComponentUpdate properly.
This library basically encourages you to use React's "PureComponent", which automatically does that calculation to see if the props have changed for you, thus giving you a huge speedup since only the components that need to update will.
- PureComponent was only added relatively recently.
- While shallow equality comparisons are relatively fast compared to deep equality comparisons, they still burn CPU. There's also a number of reasons why props could have changed, such as object literals being declared in the parent's `render` method, or the component receiving other components via `props.children`. In those cases, the "pure" comparison will fail every time, and be useless.
- There is no "default" per se. Application components explicitly extend a React component base class - either React.Component, or React.PureComponent.
https://facebook.github.io/react/docs/react-component.html#s...
I'm quite happy that this is being utilized by so many people :-)
While in development mode it warns of changes to the Redux state, without having to commit to something like Immutable.js.
Ironically, it's used within fraternities all the time as a self parody. I was in one for years and never heard anyone say it in a serious matter. Essentially fraternities use it to troll people that already dislike the subculture.
Not judging the merits of the software but rather promoting inclusiveness.
Are people really that uncomfortable with the idea that the words they use affect people?
We have real problems to care about. I have had people at work team up to give me a beating (got away by getting hold of a weapon and finding a corner, 15 years ago).
I've seen girls been judged harder, backstabbed by project managers (she did a great job). I tried to defend her.
And so on.
SJW however are all about telling me what words to use or not. They are happy to get people evicted from PyCon for nothing more than they have provably done themselves. They make it hard to have a normal conversation because all of a sudden a word you use is offensive (sorry, not a native speaker so I don't know every connotation.)
In this case it even seems obvious that someone is poking fun at the very thing. Basically they are on the same side only someone must use the opportunity to try to derail and others must upvote it so it ends on top of the comments :-|
The thing is, if you don't like it and get stuck on lingo, there's a good chance you're going to be left behind by the future. Your complaint is a symptom of falling into the out-group of the cutting edge, into becoming part of The Previous Generation.
I don't think people should have to stick to any "business speak" when working on open source software. You're doing it for fun, and for free, who cares?
This is how the "get off my lawn" mentality happens. Older generations don't just become cranky and cantankerous — society shifts out from under them in ways that go against the norms they're accustomed to while they hold the line on the way they perceive that things used to be.
Note I'm not saying that this is the direction things are ultimately going to shift toward. Just that this example is symptomatic of how generational culture shifts happen.
I've already noticed this in myself, and I'm just past thirty. I just don't "get" Snapchat, for example. It's perhaps just one thing right now, but culture changes aren't independent of one-another. You hop off the bandwagon but it keeps going and only ever becomes harder to hop back on.
It's humor. Lighthearted humor, and it's pretty hilarious to see everyone here get completely puffed up and bent out of shape about it, entirely because It Doesn't Conform To The Language Convention You're Supposed To Use Here.
Professionals push back towards professionalism, which should be free from micro-culture in jokes. The profession is international, and there are many indulging in this who do not have the perspective to recognize the actual cost of insularity.
More to the point bro-grammer crap is explicitly barrier-raising. Clique-based behavior, however graced with knowing winks, led directly to the current crisis of culture in the Valley in general, and start-up culture in particular.
As such it is most definitely at best in the category of funny-once.
And the joke played out long ago.
Because I have a definition that states you use the best tool for the job at hand, rather than choosing (yes, choosing) to complain loudly about poorly-described-and-argued ancillary matters which don't directly impact the operation of said tool.
I reject the idea that "professionalism" means that the cheeky, mischevious humor that has basically defined the hacker spirit for decades must be stamped out or suppressed.
echo "This is available on most of the servers that run the internet" | cowsay -f head-in
I think the programming profession has always been a pretty relaxed culture.Even if the tone is being used facetiously -- especially when it is being used facetiously -- we must be clear in communicating what behavior is and isn't acceptable. Failing to do so makes women feel uncomfortable, and teaches impressionable young coders (the college kids that typically have time to write sarcastic open-source one-off projects) that this kind of thing is okay.
Honest question, are you a woman? I generally agree that our industry has to do a lot more work to make everyone feel included and utilize all the talent available. But I disagree that using the word 'bruh' should be discouraged, or that it correlates with inappropriate behavior. Especially if it's anecdotal, its just correlation, not causation, and shouldn't be read into.
(Unless 'bruh' has a meaning other than 'bro', short for 'brother', that I don't know about).
These aren't white supremacist dog whistles. I think your response is totally appropriate if the package included "14/88" and "HH". It's over the top and betrays your own biases against men when pointed at "bruh" and "gainz".
Teaching that what, exactly is ok? Using the word "bruh"? In all seriousness, how old are you?
Plenty of people use that word, and it's not just guys. Is it on the immature side? Yes, but it's not really condoning whatever behavior. Unless you have data backing that assertion, you are just projecting from a mere readme file.
>gainz
These terms come from the fitness world. At first glance, it seems you're implying that the fitness world is full of gender discrimination etc.
FWIW bro (brah, bruh, etc.) is commonly used gender neutrally, much like dude.
I'm all for inclusion but I would hardly consider facetiously using brah and gainz as offensive or misogynistic.