Today I looked into the performance of different layout modes in CSS. I was curious if it takes the browser longer to lay out elements in a grid vs. Flexbox vs. flow layout.
TL:DR; they're all plenty fast ⚡️ but there are small differences.
Info in thread 👇🏻
For the benchmark, I created an app that renders 1000 random items, with a couple HTML tags in each one. I trigger a re-render, and measure how long it takes to recalculate layout.
Specifically looking for the time spent in this step:
1. Regular flow layout. No CSS on the container.
Average layout recalc time: 22.3ms
I imagine this is the lowest it could be, since each element fills the available width. No "interplay" between children.
This will be our baseline!
2. A flex column.
Very similar layout to the last element, except that margins don't collapse anymore.
Average layout recalc: 22.8ms (+2% slower, but really it's a wash).
Makes sense, browser isn't doing much different!
3. A flex row, with `flex-wrap: wrap`, and min/max sizes on children
This one requires a bit more computation, since the browser has to decide where the lines wrap.
I'm surprised that this one is slower than the 5-col one! It seems to be much more dynamic.
I repeated the experiment, same result.
These numbers are all recorded on a powerful iMac Pro, but I repeated the tests* on my budget Xiaomi Redmi 7A phone, a popular low-end smartphone in India.
* I couldn't be fussed to figure out how to get Chrome devtools running on Android, so I instead measured the entire React re-render time. On PC, the layout recalc is about 20% of the total time, so I took 20% of the mobile re-render times. Not perfect, but probably close enough.
My takeaway: there is a cost when it comes to using dynamic layouts, but that cost is quite small in absolute terms.
Even on a low-end device, using Grid layout probably won't increase render times by a noticeable amount 😄
There is a caveat, which is that synthetic benchmarks are synthetic. Your app might have a very different tree shape, which might brush against edge-cases not present here.
Every situation is unique, which is why it's important to profile!
I've seen a couple "CSS Grid is slow, use Flexbox instead" takes, and I feel much more comfortable now saying that you should ignore them 😅 the folks working on browsers are super smart and they wouldn't ship a layout method with huge performance problems.
Given the sheer volume, I'm actually kinda impressed with how well it held up 😅
I think my takeaway is the same: don't be afraid of Grid, use it when it makes sense to use it. But do check to make sure it doesn't cause problems for you: there may be times where it's slower!
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Heard from some folks that are concerned about the effect it'll have on artists. Wrestling with this a bit.
In my view, it's similar to the effect that Squarespace had on web developers. There's still plenty of demand for us, but it changed a bit.
Essentially things shift upwards a bit. It's less common to get paid $500 to build a website for your local bakery, but still plenty of opportunities building dynamic products for businesses with big budgets.
This style removes the "ugly" focus ring on inputs and links, but it means keyboard users can't navigate; it totally breaks the experience for them (and any non-mouse users) 😬
A thread with some solutions 🧵
First, some quick options:
• Leave them as-is! Outlines aren't so bad.
• Provide an alternative focus style, like changing the background color, or adding a border.
There's a nifty new pseudo-class you may not be aware of, though…
🌠 The `:focus-visible` pseudo-class is just like the `:focus` one, but it only matches when the browser determines that a visible focus state is necessary (eg. not a mouse user).
Keyboard users will see the focus rings, but mouse users won't.
At a couple jobs now, I've been tasked with reviewing incoming applications, so I've read _a lot_ of cover letters. IMO, a lot of them miss the mark 😬.
Today I thought I'd share some cover letters I've written which led to an offer, + some cover letter tips.
This letter isn't my best work, but it tells a compelling story about why I'm passionate about the space + the organization. Could be improved by sharing more about my skills/background
Letter 2: Glitch
I'm proud of this letter. I cover why I care about their mission (online code education), their product (mentioning specific features), and why my skills/background are valuable to them in their mission / for their product.