4 ms·
Drawing Text Isn't Simple: Benchmarking Console vs. Graphical Rendering
- krstffr 1y agoThis website almost crashed my m1 macbook pro (renders at 1 fps or something), so I guess point taken: rendering text is not simple!
- dist-epoch 1y agoAnd on my desktop, scrolling this page is painfully slow. Author: frontend technical lead, setting high code standards
- eviks 1y agowhat's worse is that scrolling doesn't actually work unless you have the text area focused/under the wheel... very weird. Which is even worse for PgUp/Down as who would think to focus the area first for scrolling???
- doodpants 1y ago> who would think to focus the area first for scrolling??? Sadly, this problem is common enough that click-before-keyboard-scrolling has become second nature for me.
- coxley 1y ago> Author: frontend technical lead, setting high code standards Haha, to be fair it's common to half-ass personal projects even if it's your primary domain.
- wmanley 1y agoLooks like it's caused by `backdrop-filter: blur(6px);` on `.menu-content`. After disabling that it's slow, but not that slow. Edit: This is with Firefox 144 on Ubuntu 22.04
- wmanley 1y agoIt's also perfectly responsive if you disable JavaScript. Maybe something related to the --positionX and --positionY CSS variables that are updated on every mouse move?
- wmanley 1y agoNo, actually the biggest difference is removing the `filter` property from the `.wave2` class which is used for rendering the background. With that removed the page is responsive even with the backdrop-filter - and it makes no visual difference AFAICS.
- deejayy 1y agoThanks folks for all the suggestions, I've rewritten the whole page :)
- jeffbee 1y agoWith what browser? Seems fine with Chrome.
- 9999_points 1y agoThis is "an entire doctoral research project in performant terminal emulation". https://github.com/microsoft/terminal/issues/10362#issuecomment-862844333 https://github.com/microsoft/terminal/issues/10362#issuecomm...
- bardak 1y agoI was wondering if Casey would end up a mention on this topic.
- jiggawatts 1y agoThat really was just the most absurd argument for Microsoft developers to engage in. It felt like a parody of the "optimisation is unnecessary because us developers are such Prima Donnas and simply toooooo expensive to lower ourselves to such levels" attitude that some people have. He used a cache. A simple hashtable. That's it. He got an absurd speedup of something like hundreds of times faster. What are developers smoking these days that they can't even envision ever doing something like this without undertaking a research program? To this day people will debate this, as if there's a valid debate to be had! "No, no, no, it's premature to optimise software that is... being released to a billion users in production." "Casey is adding unnecessary complexity that will be hard to maintain... by using a fraction of the code Microsoft did to solve the same problem." "It must be full of errors... well... other than the superior Unicode compliance." "It's so much longer to develop high-performance code... the evidence is that it took Casey two weekends to write a nearly complete terminal emulator!" Etc... Look where we are today. Microsoft still steadfastly refuses to even look at Casey's solution, let alone adopt it wholesale. Years later there are still blog articles being written about the performance issues of the Windows Terminal. PS: Notepad and Calculator got the same "treatment" and now struggle to keep up with key presses.
- xeonmc 1y agoOn the other hand you have the new Microsoft Edit which is some guy’s weekend TUI project that got canonized by MS.
- 1y ago
- bob1029 1y agoSDF seems to be one of the better solutions for text rendering. Valve had this problem solved since 2007. I'd argue this technique is a big part of what gave TF2 its impressive visual style. That game ran at 100+ fps on hardware like the 8800GT at the time. https://www.redblobgames.com/x/2403-distance-field-fonts/ https://www.redblobgames.com/x/2403-distance-field-fonts/
- jayd16 1y agoSDF is awesome but even then it's not a silver bullet. It's a raster technique and some people want vector fonts or subpixel rendering.
- corysama 1y agoI can imagine subpixel rendering being rather easy for SDF fonts. But, I can’t say I’ve seen it done.
- mfabbri77 1y agoI don't know how common it is in fonts, but for generic 2D vector graphics, problems arise from the management of self-intersections, i.e., the pixels where they fall. With an SDF rasterizer, how do you handle the pixel where two Bezier curves intersect in a fish-shaped path? For this reason, more conventional rasterizers with multisampling are often used, or rasterizers that calculate pixel coverage analytically, also finding intersections (sweepline, Bentley-Ottmann).
- jayd16 1y agoHmm I'm not sure I quite understand your question. The renderer uses predefined textures of signed distance fields. Essentially you're building a gradient out from your source vector. You can tweak how that texture is built and it doesn't need to be strictly the true distance. In theory you could handle it however you want. You could make an SDF texture of a figure eight where the inside of the eight is purely zero and only the outside has a gradient. If you built a texture like this then your stroke with would only ever grow out of the shape. This is an example of how SDF is very powerful. If instead you're asking about the precision with regards to the infinitely small point of an intersection of two vectors it's actually not an issue at all. The technique uses the usual texture sampling pipeline such that the render will be as sharp as your SDF texture and as alias free as your mitmaping allows.
- jayd16 1y agoStupid question but what are the units used in the results tables??
- unwind 1y agoMeta: this is kind of a repost, not even a month since last time [1]. [1]: https://news.ycombinator.com/item?id=45580559 https://news.ycombinator.com/item?id=45580559
- cluckindan 1y agoI wonder how the GPU version is implemented. One quad and one texture draw per glyph sounds very not scalable, but one quad per terminal, one texture atlas and one shader to draw glyphs from the atlas already sounds much better.
- henning 1y agoOne quad per glyph is very scalable, especially if you use instanced rendering. Each quad is just reading from a single texture atlas. GPUs are beastly blitting machines. Runs at ~1500 FPS with a 6K screen of full text on my machine even when text is being updated at about the pace of a 150 WPM typist but you only update quads that strictly need to change and store font metrics on the GPU in a buffer. A full screen refresh where you send quad data for 750 Lorem ipsum paragraphs every frame runs at 300 FPS on my hardware.
- Snild 1y agoA terminal maximized on my screen says: ~$ echo $((2 * LINES * COLUMNS)) triangles 34272 triangles That's nothing for a modern GPU. For example, this benchmark[1] says to expect on the order of 10-800 million tri/s. At the low end of that, you'd have a frame time of 3.427ms -- 292 fps. The original Playstation could do 180 000 textured polygons per second[2], so it could've managed ~5 fps. Of course, you wouldn't render that many chars at its available output resolutions anyway. :) [1] https://github.com/ctsilva/triangle-rendering-benchmarks#:~:text=Expected%20Performance%20Ranges https://github.com/ctsilva/triangle-rendering-benchmarks#:~:... [2] https://en.wikipedia.org/wiki/PlayStation_technical_specifications#:~:text=180,000%20with%20texture%20mapping https://en.wikipedia.org/wiki/PlayStation_technical_specific...
- jayd16 1y agoBut if they naively execute 15120 draw calls...
- samdoesnothing 1y agoSame texture so a single draw call probably?
- JodieBenitez 1y agoAnd another website made unusable thanks to inconsiderate use of javascript.
- henning 1y agoCaching the fonts to a texture atlas is not an unusual idea. https://github.com/memononen/fontstash https://github.com/memononen/fontstash is a well known example of this. Odin has a native port meant to work in conjunction with its bindings to NanoVG. The Odin code is coupled to stb_freetype.
- rhdunn 1y agoHere's Sabastian Lague's (Coding Adventure) video on font rendering -- https://www.youtube.com/watch?v=SO83KQuuZvg https://www.youtube.com/watch?v=SO83KQuuZvg.
- Sharlin 1y ago> So I tried something unconventional: draw each character once, cache it as a texture, and then just copy those textures around. That’s more like the most conventional way to draw characters ever. Nobody goes around rendering filled Béziers any more than absolutely necessary. And conventionally conventionally, fonts were bitmaps in the first place!
- taeric 1y agoYeah, I confess I would have assumed that this was more common than otherwise. Makes me curious how much of computing is losing perceived speed because we have moved to calculating everything on the fly? Easy example is website layout. Yes, some dynamic sites need to calculate a ton on the fly. Most sites, though, probably don't need to reflow everything nearly as often as they do. And fitting everything into the mechanism that is the document flow remains baffling to me.
- mr_toad 1y ago> And conventionally conventionally, fonts were bitmaps in the first place! Bitmaps in ROM on early machines. https://en.wikipedia.org/wiki/Motorola_6845 https://en.wikipedia.org/wiki/Motorola_6845
- estimator7292 1y agoBitmaps in diode arrays on even earlier machines
- talkingtab 1y agoMSDF is worth looking at: https://github.com/Chlumsky/msdfgen https://github.com/Chlumsky/msdfgen and https://steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf https://steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007... The context is GPU's, things like three.js But yes, drawing text is hard.
- HackerThemAll 1y agoI recommend the following reading (from https://news.ycombinator.com/item?id=36478892 https://news.ycombinator.com/item?id=36478892). https://faultlore.com/blah/text-hates-you/ https://faultlore.com/blah/text-hates-you/