惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
D
Docker
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - 司徒正美
博客园 - Franky
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
AI
AI
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Secure Thoughts
博客园 - 聂微东
L
LINUX DO - 最新话题
U
Unit 42
SecWiki News
SecWiki News
A
Arctic Wolf
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Visual Studio Blog
量子位
The Cloudflare Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
Last Week in AI
Last Week in AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
Latest news
Latest news

Ben Frain

So, you want a React modal that uses the <dialog> element and transitions in AND out? Scroll indicators on tables with background colours using animation-timeline Review: SoundPEATS Clip1 Open ear clip-on headphones VS Code – highlight just the active indent guide Review: MoErgo Go60, a split ergonomic and fully programmable keyboard Review: Kinesis mWave mechanical ergonomic and programmable keyboard iOS26 Safari theme-color/tab-tinting with fixed position elements is a mess New Book: Responsive Web Design with HTML5 and CSS, 5th Edition Use @supports with a proxy feature/value for features you can’t test for (@starting-style) First adventures in View Transitions Review: Benq Screenbar Pro and Halo lightbars. The kit you never knew you needed! Center items in a container, and make then left aligned when they overflow A single element CSS donut timer/countdown timer, that can sit on any background Review: Open Ear Headphones – Bose Open Ultra v Huawei FreeClip In search of the perfect autocomplete for CSS Managing multiple versions of node, without NVM or additional tools Review: Keychron Q14 Max Alice 96 Key mechanical keyboard NEW VIDEO COURSE: Responsive Web Design with HTML5 and CSS Review: Advantage360 Pro Signature Edition 2024 mechanical ergonomic keyboard More Keys or Fewer Keys for mechanical keyboards Yes! You can use position: sticky and overflow together Neovim – how to do project-wide find and replace? Review: Keyboardio Model 100, split, wooden, mechanical keyboard Struggling to learn SwiftUI How to create rounded gradient borders with any background in CSS How to get equal size icons in the cmp completion menu of Neovim with Kitty terminal Review: Dygma Defy, split, mechanical, programmable ergonomic keyboard What’s the best way to reset WAAPI chained animations? Using CSS @property inside shadowRoot (web components) workaround Dynamically create a ref for items when iterating over them in lit.dev templates Selecting and pausing running animations in Lit Web Components New Web APIs — a popover on top of a dialog element can’t be interacted with? Review: ZSA Voyager, split, mechanical keyboard Russel Brand, narcissism, and a sadly common pattern… When it comes to text editors, I feel like Goldilocks Simple settings for writing and converting markdown with Sublime Text Review: The ZSA Platform tenting kit for the Moonlander keyboard Logitech MX Master 3/3s scroll wheel fix Building a line graph with CSS clip-mask Review: Dell 6K 32″ Monitor U3224KBA I broke my keyboard! Swapping the key switches in the Kinesis Advantage360 Pro HUGE macOS Productivity boost: Set-up simple, keyboard only, instant App switching and arrangement Adding to $PATH for a central location for Neovim/NPM tools Neovim Power Tips: Volume 2 Review: MoErgo Glove80, split, wireless, columnar ergonomic keyboard with RGB Review: Kinesis Advantage 360 Pro — split ergo mechanical keyboard Review: Dactyl Manuform – an ergonomic, custom built mechanical keyboard How to animate along an SVG path at the same time the path animates? Getting the context of Web Components (lit)
Is CSS Grid really slower than Flexbox?
Ben Frain · 2024-08-06 · via Ben Frain

Search for ‘is CSS Grid slower than Flexbox’ and you’ll find a few posts explaining that it is. In my experience, even if it was, it is not anymore. Well, not for the scenario I tested anyway.

The tests

I took 200 elements with a nested element. The DOM for each was like this:

<div class="wn-Item">
    <div class="icon"></div>
    item2
</div>

The CSS looked like this for the Flex variant:

.wn-PreMatchGroup {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 100%;
    max-width: 500px;
    margin: auto;
}
.wn-Item {
    display: flex;
    width: 100%;
    align-items: center;
    height: 45px;
    gap: 0 10px;
}
.icon {
    width: 20px;
    height: 20px;
    background-color: gold;
}

And like this for the Grid variant:

.wn-PreMatchGroup {
    position: relative;
    display: grid;
    grid-template-columns: 1fr minmax(auto, 500px) 1fr;
}
.wn-Item {
    display: grid;
    grid-auto-flow: column;
    width: 100%;
    place-content: center start;
    height: 45px;
    gap: 0 10px;
    grid-column: 2;
}
.icon {
    width: 20px;
    height: 20px;
    background-color: gold;
}

The idea being that there was some computation to be done regarding the maximum width the column should be, and how the ‘gutters’ were made each side.

To measure performance I used a snippet from MDN:


    const observer = new PerformanceObserver((list) => {
      list.getEntries().forEach((entry) => {
        console.log(
          `The time to ${entry.name} was ${entry.startTime} milliseconds.`,
    );
    // Logs "The time to first-paint was 386.7999999523163 milliseconds."
    // Logs "The time to first-contentful-paint was 400.6999999284744 milliseconds."
  });
});

observer.observe({ type: "paint", buffered: true });

You can grab/view the files here: https://github.com/benfrain/css-performance-tests

Results

Take a look for yourself in the browser but over 20-30 refreshes of the page I see no significant difference, using Chrome 127 or Safari 17.6. 20 results below. I got bored after than…

Run Chrome Flex Chrome Grid Safari Flex Safari Grid
1 58.20 62.80 15.00 16.00
2 49.70 61.00 10.00 16.00
3 51.80 43.00 13.00 17.00
4 56.60 48.69 14.00 16.00
5 54.60 62.00 13.00 19.00
6 50.60 50.40 13.00 18.00
7 61.80 48.79 15.00 20.00
8 50.60 51.90 15.00 19.00
9 48.69 58.69 16.00 20.00
10 51.00 60.30 13.00 21.00
11 49.59 45.50 16.00 18.00
12 56.19 49.40 17.00 20.00
13 60.19 49.30 13.00 18.00
14 62.00 52.59 16.00 17.00
15 67.79 52.39 15.00 21.00
16 59.70 56.50 15.00 19.00
17 50.30 45.60 16.00 13.00
18 51.50 62.50 15.00 17.00
19 56.90 44.00 15.00 16.00
20 51.19 49.80 17.00 24.00
Average 54.84 52.75 14.6 18.25

Summary

I’ve done a few of these kinds of tests over the years.

As ever, it is essential to test CSS performance dogma against your own real world scenario. I’m not saying Grid will never be a problem, or Flex for that matter. But don’t assume it will be either.