Better HN
topnewbestaskshowjobs
Log inSign up

raphlinus

14,081 karma · joined Mar 7, 2014 (12y ago) · 1,887 submissions

I do research on fundamental UI technology and 2D graphics, with a focus on Rust and fonts. @raph@mastodon.online
Submissions

comment 10y ago · link · parent

People interested in this stuff might also want to take a look at the rope in https://github.com/google/xi-editor. It's not a finger tree, rather it's based on a B-tree, which is simpler but doesn't have quite as good asymptotic guarantees for operations at the beginning and end of the sequence. Also, Rust.

comment 10y ago · link · parent

I use monoid homomorphisms extensively in xi-editor, and have a couple of slides on it at my RustConf talk earlier this month. I hope to be writing up the ideas in more detail soon (both what I've implemented, and speculative explorations such as doing incremental syntax highlighting).

comment 10y ago · link · parent

Or use fancy-regex. Not ready for prime-time, but potentially the best of both worlds.

comment 10y ago · link · parent

I was also there as one of the presenters, and concur, it was a great experience. The strength of the community is absolutely one of the threads that ran throughout the conference. I've been involved in open source a long a long time and had sadly revised my expectations downward, but Rust is going a long way towards restoring my confidence.

Kudos and thanks to the organizers!

comment 10y ago · link · parent

Someone claims (https://groups.google.com/forum/#!topic/sci.crypt/JSSM6Nbfwe...) that it's just as easy to spoof 64 bit as 32 bit keys. I have no idea whether to believe him, but even if he's full of it, it's prudent to assume that if the 32 bit attack was practical 20 years ago, 64 bits is within reach today.

comment 10y ago · link · parent

Just to point out, this attack goes back at least 22 years. According to [this thread](https://groups.google.com/forum/#!topic/sci.crypt/JSSM6Nbfwe...), credit is due to Paul Leyland.

comment 10y ago · link · parent

Thanks for the detailed comment.

I think you're going for something much more complicated than what I had in mind. My idea is simply to have two modes other than accum buffer -> 8 bit alpha mask. One would be accum buffer + constant RGBA color -> update RGBA buffer. (By update I mean read an RGBA pixel, do the compositing, and write the composited pixel in place). The other would be accum buffer + source RGBA buffer -> update RGBA buffer. Of course, it's possible to imagine interleaving even more operations in the generation of the source RGBA buffer, but at some point the register pressure overcomes the r/w bandwidth.

Prefix-sum is not a particularly fast SIMD operation, due to the horizontal data dependency. I chose it for font-rs because I don't know of any faster ones that can get the job done. For just computing gradients, it's almost certainly going to be faster to compute it directly (it's simple multiply-add in the case of linear gradients) than to try to strength reduce. The same is no doubt true for SVG radial (cone) gradients.

When the gradient doesn't have any sharp creases or singularities, a very reasonable strategy is to compute it in lower resolution and then up-res, say 2x or 4x to keep the math super-simple. When it does have creases, it might make sense to decompose into regions and use different approaches in different regions.

In any case, it sounds like you may be re-inventing Cairo or Skia here. Might make sense to take a closer look at what they do and whether there's truly any low-hanging fruit left. I know that Skia has a bunch of SIMD optimizations already.

But this is fun stuff to think about and experiment with. I certainly don't want to discourage you.

comment 10y ago · link · parent

Total agreement, well said.

comment 10y ago · link · parent

The specific claim I'm making is that Rust has language (in the form of making it the default in `for` loops) and library (in the form of the `Iterator` trait) support for this pattern.

Further, Rust's monomorphizing approach to generics means that you can count on efficient code. Iterators over a slice typically elide the bounds checking, reliably.

Of course you can use these patterns in other languages, but you lose something, specifically, clarity and safety. I believe that's the reason you see them used all the time in Rust and rarely in C and C++.

comment 10y ago · link · parent

I think there is value in applying these ideas to SVG rendering as well. There are of course a bunch of things that are different. For SVG, buffers get large enough you'd probably want to do _some_ banded rendering because the accumulation buffer might otherwise get too big.

Another serious potential win in SVG is that you might be able to interleave the area integration with alpha compositing / masking. Could end up pretty darned fast.

comment 10y ago · link · parent

I did some measurements of rusttype and found it to be even slower than FreeType. That said, this is all open source and so I have confidence that the improvements will flow all the way, either through rusttype using the font-rs rasterizer, or font-rs becoming robust enough for downstream like Redox and Piston to adopt.

comment 10y ago · link · parent

Not directly. My approach in Xi is to use the system text stack (including font rendering) for a variety of reasons, including consistency of appearance with other text on the system, keeping the front-end small and lightweight, and being able to exploit hardware acceleration to the max.

That said, my hope is that these ideas make their way into at least one system text stack running under Xi. The ideas are simple to implement, and I hope I've made the case that the performance improvement is compelling enough to pursue.

1873.

Inside the fastest font renderer in the world(medium.com ↗)

35 points · by raphlinus · 10y ago · 2 comments

comment 10y ago · link · parent

Thanks for your thoughtful comments. I'll try to address some.

Using ropes is a tradeoff. A gapped buffer is viable for the reasons you state, but I think ropes come out ahead for what I'm trying to do. It's not so much the cost of filling the gap, as that ropes really facilitate parallel, incremental, and asynchronous computation. For example, I want the "save" operation to write a snapshot of the current buffer to disk, while still being fully editable. The snapshot operation is trivially easy and fast with immutable ropes, but if you tried to hack something like that on top of a gapped buffer, it would increase complexity dramatically.

If you look at the implementation of my Unicode line breaking algorithm, you'll see that the indirection cost of the rope abstraction is minimal. In fact, it _flies_ - in my tests, it's about 3x faster than ICU working on a contiguous string. This is because it's able to work on a leaf at a time. The same can be done for search, etc. Yes, it'll require some reimplementation of string basics, but I personally find that kind of thing fun.

I'm still working out the plugin story. Quick answers to your questions though. A syntax highlighting plugin sees a window of the source buffer (effectively a cache, with invalidation by RPC). I'm thinking a contiguous buffer for the window, not a rope - it'd be bounded by a few megs. For a huge file, computing the syntax highlight of what's off screen can be slow. In no case does it block typing, worst case there's a lag before the colors resolve. The plugin sends the annotations back as rich-text spans, which are stored in the core. Scrolling is instant and doesn't inform the plugin. The autocomplete plugin will almost certainly be separate from the syntax highlighting one (but presumably an author could create a combo plugin if it had advantages).

This doesn't address everything you brought up, but hope it helps illuminate some of my thinking.

comment 10y ago · link · parent

The specific thing that went wrong was trying to use the homebrew version. 4 just worked out of the box, no hassle. I do of course have access to a Linux machine, but it'd be convenient to do development on my Mac as well. I'm willing to give it another shot but need to be convinced it's worthwhile.

comment 10y ago · link · parent

I'm hoping soon but make no promises.

comment 10y ago · link · parent

Probably not a lot. The Swift code is basically for plumbing to the GUI toolkit. All the actual text processing is done in the core.

comment 10y ago · link · parent

Qt 4 or 5? I had difficulty getting even "hello world" running in 5, and the size of deploy binaries (~16M) was scary. Maybe that doesn't matter so much if it'll primarily be using system libraries.

comment 10y ago · link · parent

I think a Vim mode will be possible one way or other. I'm not sure having all interaction mediated by plugins is the best way to accomplish it.

comment 10y ago · link · parent

The main thing I'd add to http://www.basschouten.com/blog1.php/font-rendering-gdi-vers... is that DirectWrite looks very smooth on high-dpi displays while GDI+ is quite grainy.

comment 10y ago · link · parent

I'm leaning towards Gtk+ because I'm more familiar with it (I used to be very involved in that community, in fact) and because I know its Unicode support is good.

comment 10y ago · link · parent

I haven't started implementing plugins yet, so details are still vague. General thoughts, they communicate with the core through a simple JSON-based protocol, so can be written in any language you like. I imagine Python will be one of the popular choices. Among other things, they'll be able to annotate the text with rich-text spans, for things like syntax coloring. Also, I'm planning for them to be async, so they won't slow typing even when they're busy computing.

comment 10y ago · link · parent

I've been playing a bit with the various choices (there are so many!) and am leaning in the direction of C# + WPF + Windows.System.Media for the text drawing. Using something based on DirectWrite rather than GDI+ is important to me because of text rendering quality. I have basically ruled out Windows Universal because it feels a lot clunkier.

But I'm very much open to ideas from more experienced Windows devs who understand the tradeoffs better.

comment 10y ago · link · parent

I'm basically planning on following Sublime Text's keybindings except when there's good reason not to.

comment 10y ago · link · parent

NeoVIM is great, and obviously it has been inspiration. I think it remains to be seen whether NeoVIM can deliver an experience that feels like a modern editor. My experience is that projects which attempt to layer a GUI on top of an existing, mature console UI end up leaking bits of the underlying UI. I'm thinking mostly of the various TeX shells here.

A large part of my motivation for starting this project is to explore how suitable Rust is for this kind of work. End users shouldn't have to care, they should judge it strictly by the quality of what it delivers. But I'm hoping this project will be interesting to Rust programmers for a number of reasons.

comment 10y ago · link · parent

Rust is working out very well so far. If you look at the rope implementation, you'll see that it's high level and mathematical almost like a functional language, but performance is first-class. I'm also very much looking forward to retrofitting parallelism using libraries such as Rayon and crossbeam. I'll probably write a retrospective when I'm farther into the project.

My current development environment is just Sublime Text for the Rust parts, and Xcode for the parts written in Swift.

comment 10y ago · link · parent

It's a project by a Googler (me), but it's a personal (20%) project, not an official Google one.
1
5960616263