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 6y ago · link · parent

I just want to say that I really admire and support what Zig is trying to do here. It takes guts to try to launch an ecosystem from a fun hobby to something that can be used in production and hopefully sustain its contributors. They're not there yet, but it looks like they may well be on that journey.

This thing looks very unpleasant, but hopefully it conveys the message that Zig is potentially valuable. Figuring out how to fund such a project and organize the community is a hard problem, and again I wish them well in finding a good path.

comment 6y ago · link · parent

Not at all, I thought it was a fascinating conversation. As you probably know, I worked on low-latency audio a bit as a "serious 20%" project while on Android, so I'm very interested in audio as well, and I think the two communities have lots to learn from each other.

comment 6y ago · link · parent

If you're animating (or doing smooth window resizing), then your "present" request includes a target frame sequence number. The way I analyze the text editor case is that it's something of a special case of triple-buffering, but instead of spamming frames as fast as possible at the swapchain, you do multiple revisions for a single target sequence number. The last revision to make it ahead of the beam wins. If you have a smooth clock animation in addition to some latency-critical input sensitive elements, then the clock hands would be in the same position for each revision, only the other elements would change.

If done carefully, this would give you smoother animations at considerably lower power consumption than traditional triple buffering. It's not the way present APIs are designed today, though, one of my many sadnesses.

As I hinted, this is a good way to synchronize window resize as well. The window manager tells the application, "as of frame number 98765, your new size is 2345x1234." It also sends the window frame and shadows etc with the same frame number. These are treated as a transaction; both have to arrive before the deadline for the transaction to go through. This is not rocket science, but requires careful attention to detail.

comment 6y ago · link · parent

I think most modern OS kernels support realtime threads with a guarantee strong enough to support this kind of workflow. As Paul Davis points out in a different comment, the latency needs of audio and video are actually more similar than they are different, and pro audio is possible (though still harder than it should be).

But I don't want to underestimate the engineering challenges either. You'd have to make this stuff actually work.

comment 6y ago · link · parent

We had a discussion on this in #gpu on our Zulip. The short answer is that if the screen is updating at 60fps, then FreeSync and its cousins are effectively a no-op. If the display is mostly idle, then there is potentially latency benefit in withholding scanout until triggered by a keypress. Older revisions of FreeSync have a "minimum frame rate" which actually doesn't buy you much; 40Hz is common: https://www.amd.com/en/products/freesync-monitors

comment 6y ago · link · parent

Apologies for getting your name wrong; it should be fixed now. I also made some other changes which I hope address the points you brought up. I didn't know about Windows 2000 layered windows, but I think the section on which systems had process separation was just confusingly worded.

Counting Intel, most (by number) desktop devices have pretty sophisticated hardware layer capabilities. Sky Lake has 3 display pipes, each of which has 3 display planes and a cursor. The multiple pipes are probably mostly used for multi-monitor configurations, but it's still a decent setup. From the hints I've picked up, I believe DirectFlip was largely engineered for this hardware.

There are lots of interesting latency-reducing tricks. Some of those might be good inspiration, but what I'm advocating is a general interface that lets applications reliably get good performance.

Thanks for the discussion!

1087.

The compositor is evil(raphlinus.github.io ↗)

248 points · by raphlinus · 6y ago · 175 comments

comment 6y ago · link · parent

Also https://crates.io/users/tony-iqlusion

That person is definitely not helping the perception that a significant fraction of the cryptofinance community is scammers, and that their presence has a negative effect on the community.

comment 6y ago · link · parent

The Dyck language I was already aware of; I linked it in the previous post in the series. But the bicyclic semigroup was new to me. Yes, the bones of it are very similar to my "stack monoid;" if you erase the actual element values of the stack contents and just count the lengths, it's clearly the same thing. No doubt there's some theory that justifies adding the elements back in as well.

I'll have to check out the Kmett talk - from the description it sounds very interesting.

comment 6y ago · link · parent

Thanks for the reference, it's definitely relevant. I took a pass over the paper somewhere between skimming and reading, and, while it's definitely in the ballpark of deriving parallel programs from sequential, it's also pretty clear their source language can't express the stack monoid problem because it lacks a "cons" operation; basically it seems to be for various fancy reduction problems where it consumes a sequence and spits out a scalar. On a quick read, I have no idea whether that's a fundamental limitation or something that could be extended.

I think examples like generating mergesort from insertion sort are maybe trying to be too clever. I mostly just want something that lets you slice up the problem into chunks, process each chunk in parallel, then combine them back in ways that don't kill performance on modern GPU hardware.

comment 6y ago · link · parent

Yupyup. For those of us who don't just automatically know what a semigroup action is, Dan Piponi's blog on using monoids to do incremental regular expression matching is probably a good read: http://blog.sigfpe.com/2009/01/fast-incremental-regular-expr...

comment 6y ago · link · parent

Yes, that's basically it. There are more details, like how I think this can efficiently be implemented on GPU hardware (it's not clear at all that this is the case), but you and GP have captured the basic motivation and idea.

comment 6y ago · link · parent

Super! My understand is that Krita's distribution through app stores has a similar flavor - it's pure GPL, no tricks, but people pay for the convenience and assurance of downloading the official version of the app.

My personal feeling is that as PC's become more locked down and less under user control, paying for the digitally signed version might increasingly become a viable business model. Trademarks and TOS enforcement might be a more effective moat against being undercut than copyrights and licenses.

comment 6y ago · link · parent

The bell it rang for me was [1], which has come up in discussions with Patrick Walton about maintaining a sort order for coarse rasterization in 2D vector rendering. Taking another look at that, it seems like they propose both bounded k-stacks and linked lists as solutions for recording all the fragments to be combined for transparency blending, but not the hybrid of the two. I wouldn't be surprised if that's been considered.

The problem is slightly different, though, because the major focus for transparency is concurrent writing from potentially many different shaders, while in the stack case each thread can build its data structure without any concurrency or need for atomics; once an aggregate is built, it is "published" (see my prefix sum blog for details on that) and treated as immutable.

These kinds of concurrent approaches do become important for later stages in the JSON parsing process, like building hashmaps for keys in a dictionary. I'm pretty sure the whole problem is tractable and have thoughts how to solve it, but deliberately kept the scope of this blog post limited, as I figured it was challenging enough. But it's very cool to reach people who appreciate the ideas, and if you find anything else that's relevant, I'd love to hear from you.

[1]: https://on-demand.gputechconf.com/gtc/2014/presentations/S43...

comment 6y ago · link · parent

It's a good question, and it's been suggested I write a GPU compute 101. I did do a talk at Jane Street earlier in the year called "A taste of GPU compute" which has some relevant resources (a Google search on that term will give you a number of links).

I think there are probably a number of on-ramps. One easy way to get started is shadertoy, which if nothing else should give familiarity with GLSL syntax and intuition for performance in the simplest case: each "thread" computes something (a pixel value) independently of the others. You'll quickly run into limitations though, as it can't really do any of the more advanced compute stuff. I think as WebGPU becomes real, an analogous tool that unlocks compute kernels (aka compute shaders) could be very powerful for pedagogy.

I think most people that do compute on GPU use CUDA, as it's the only really practical toolchain for it. That has a large number of high quality open source libraries, which tend to be well-documented and have good research papers behind them. You can start by using these libraries, then digging deeper to see how they're implemented.

As I've been going on about, I believe this space is ripe for major growth in the next decade or so. As a rough guide, if you can make your algorithm fit the GPU compute model nicely, you'll get about 10x the compute per dollar, which is effectively the same as compute per watt. Why leave such performance on the table? The answer is that programming GPUs is just too hard. In certain areas, including machine learning, an investment of research has partially fixed that problem. But in others there is fruit at medium height, ripe for the picking. And in some other areas, you'll need a tall ladder, of which I believe a solid understanding of monoids is but one rung.

comment 6y ago · link · parent

An ultra reliable query for scammy products is "1TB USB flash drive." This product does exist in legit versions for about $200, but almost all of the (relevant to the query; many are for smaller capacities) hits are scams in the $30-40 price range. I believe these are mostly lower capacity thumb drives that have been hacked to report 1TB; this tactic has high danger for data corruption.

The fact that these listings are so easily gamed is to me a sign of something seriously wrong at Amazon. I know from experience how hard the abuse problem is (it was my job for a couple years at Google), but this should be Amazon's bread and butter.

comment 6y ago · link · parent

Good call, that rings a bell and I'll look into it. A bounded k-stack with overflow seems like a really good fit for the capabilities provided by GPU.

comment 6y ago · link · parent

A note: I just updated the post with a bunch of related work that people have sent me since I published the first draft. It also includes a bit more intuition behind the monoid.

comment 6y ago · link · parent

Also potentially relevant: Ralf, or I should say, Dr. Jung, recently completed a PhD, which I'm sure will have a lot more fascinating material for those interested in this paper. I'm hoping to find time myself to read it, but I seem to spend too much time on sites like Hacker News...

https://www.ralfj.de/blog/2020/09/03/phd.html

1100.

The Stack Monoid(raphlinus.github.io ↗)

195 points · by raphlinus · 6y ago · 47 comments

comment 6y ago · link · parent

For people who read the comments here but not the primary sources[0], you've put words into Dennis Ritchie's mouth. He did not say that UB must go, but that noalias must go. And, lo and behold, it did. So these (altered) quotes are not at all a fair characterization of what's actually in the standard.

[0]: https://www.lysator.liu.se/c/dmr-on-noalias.html

comment 6y ago · link · parent

This is not an unpopular opinion per se, but one that puts you firmly in the "semi-portable C" camp (in the "camp" model of the essay I linked in another comment), while the compiler vendors themselves have moved entirely away from that camp into the "standard C" camp. As I wrote, "The principles and practices in one camp can seem alien, even threatening to another."

comment 6y ago · link · parent

As good a time as any to pimp my own essay on the topic, from a couple years ago:

https://raphlinus.github.io/programming/rust/2018/08/17/unde...

comment 6y ago · link · parent

That's not a 1TB USB drive, it's a tapestry. Then they took the listing for that and changed it to a USB drive so they could harvest the 5 star reviews.

Amazon has turned into a flea market.

comment 6y ago · link · parent

Yup, that is a promising direction. I think a lot of my concern is around building a consensus and getting people on the same page.

comment 6y ago · link · parent

I hope Rust / Objective-C interop gets some more love soon. There are a number of pain points, including inconsistent wrapping styles (the "cocoa" crate implements things like NSView as traits on id), autorelease pools always being a pain, and a fair amount of bloat from the msg_send! macro (a lot of which is boilerplate error handling).

Not exactly obj-C, but there are also problems two inconsistent ways of wrapping other macOS types: some (like the Metal crate) use foreign_types, while others use the TCFType mechanism. Among other things, these have two different meanings for "Ref" types, which can be very confusing.

So it's possible to get stuff done, but it doesn't feel nice. By contrast, the Rust/Windows world pretty well organized, with Peter Atashian's winapi providing a solid foundation, the wio crate being a good way to get ComPtr and other utilities, and Microsoft's com-rs coming soon as a standard way to do Rust-side implementation of COM interfaces.

comment 6y ago · link · parent

I think ~warent is referring to features like ink traps, which are features that do look strange up-close, but might help increase contrast or other qualities at small sizes.

comment 6y ago · link · parent

I also had a CARDIAC, but on top of that I had a series of computers starting with KIM-1 (6502) and SDK-85 (8085, which was Intel's answer to the Z80 at the time). Fun times, and I think we've lost something since then.

comment 6y ago · link · parent

One theory on XLAT is that it's there to make it easier to adapt code originally written for 6502, where the "indirect indexed" addressing mode was popular. The zero-extended 8 + 16 addition is the same, and this would otherwise require a sequence. For example, to do code page translation on 6502 you'd definitely use indirect indexed at the core. But yeah, this is an oddball instruction, one of the most non-RISC-like in the set.

comment 6y ago · link · parent

Right, the idea that OT requires a "central server" is a bit of an oversimplification. It requires an authority that can serialize concurrent revisions into a globally consistent sequence. By far the easiest way to achieve that is an actual central server, but distributed algorithms have also been published for a long time, for example SOCT2 which uses a state vector.

The downside is the complexity. Now there are more things that can go wrong: the OT algorithm can fail (either due to bugs or because of corrupted data), and now also the distributed consensus algorithm can fail as well. When you have this level of complexity, going to CRDT is pretty appealing as an alternative.

1
363738
63