14,081 karma · joined Mar 7, 2014 (12y ago) · 1,887 submissions
comment 4y ago · link · parent
Here's my current thinking on the topic. It all depends on whether you want to model your problem as a tree or a graph (see also [1] for some great discussion of that tension). If you model your problem as a graph, then a general purpose incremental computation engine like Adapton (or Incremental or Salsa) is great. However, if your problem is a tree, then constructing the explicit dependency graph requires a nontrivial amount of ceremony. What Xilem does is represent the most common tree-structured flows of information in a very lightweight manner (mostly just plain code that builds views), while allowing you to insert arbitrary graph edges if you like with more work.
I think it's a discussion worth continuing. One thing you could do is integrate Adapton and Xilem together, where the implementation of most view nodes in the latter becomes queries into the Adapton engine. How well would that work? Really only one way to find out.
[1]: https://glazkov.com/2022/02/06/tension-between-graphs-and-tr...
542.
Xilem: An Architecture for UI in Rust(raphlinus.github.io ↗)
457 points · by raphlinus · 4y ago · 103 comments
comment 4y ago · link · parent
I personally believe it may be possible to reduce latency using techniques similar to io_uring, but it may not be simple. Likely a major reason for the roundtrips is so that a trusted process (part of the GPU driver) can validate inputs from untrusted user code before it's presented to the GPU hardware.
comment 4y ago · link · parent
The GPU is incredible at raw throughput, and this particular problem can actually implemented fairly straightforwardly (it's a stream compaction, which in turn can be expressed in terms of prefix sum). However, where the GPU absolutely falls down is when you want to interleave CPU and GPU computations. To give round numbers, the roundtrip latency is on the order of 100µs, and even aside from that, the memcpy back and forth between host and device memory might actually be slower than just solving the problem on the CPU. So you only win when the strings are very large, again using round numbers about a megabyte.
Things change if you are able to pipeline a lot of useful computation on the GPU. This is an area of active research (including my own). Aaron Hsu has been doing groundbreaking work implementing an entire compiler on the GPU, and there's more recent work[1], implemented in Futhark, that suggests that that this approach is promising.
I have a paper in the pipeline that includes an extraordinarily high performance (~12G elements/s) GPU implementation of the parentheses matching problem, which is the heart of parsing. If anyone would like to review a draft and provide comments, please add a comment to the GitHub issue[2] I'm using to track this. It's due very soon and I'm on a tight timeline to get all the measurements done, so actionable suggestions on how to improve the text would be most welcome.
[1]: https://theses.liacs.nl/pdf/2020-2021-VoetterRobin.pdf
[2]: https://github.com/raphlinus/raphlinus.github.io/issues/66#i...
comment 4y ago · link · parent
Perhaps ironically, there are some aspects of this project (parallelism and AI) that are now massively important. It's just that they were ahead of their time on those aspects, and Prolog is now largely a historical bywater.
[1]: https://en.wikipedia.org/wiki/Fifth_Generation_Computer_Syst...
comment 4y ago · link · parent
Basically, it answers the question, "why do Rust GUI frameworks use enums rather than closures for messages in the Elm update pattern?" It is very insightful, but doesn't tell the whole story. In particular, as a major counterexample, Druid does use closures for stuff like buttons, and they update state exactly as expected. That said, the Druid approach does have major drawbacks, chief among them that the app state needs a `Data` bound, which (oversimplifying slightly) means that it only works well with immutable data structures.
As it turns out, I've been thinking about how to solve this problem - closures that have convenient access to mutable app state without strange bounds on that state, or strange control flow when doing things like adding and deleting widgets, and think I've finally cracked it. I will be doing a writeup when I have time, but for the eager and curious, there is a code sketch at https://github.com/linebender/druid/blob/lasagna/lasagna/src... .
comment 4y ago · link · parent
However, I would say that a common thread is that doing this well is hard. There's no straightforward cookbook scheme that people can just implement, and there are always tradeoffs. Slug is used in a number of games (and congrats to Eric for winning those licenses), but not as far as I know in any UI toolkits, and there are reasons for that.
comment 4y ago · link · parent
There are a few related things that can be said. Doing fast, high quality font rendering on a GPU is hard; it's much easier on a CPU. Further, the traditional rasterization pipeline of a GPU is not good at rendering fonts. Fortunately, modern GPUs also have compute shaders, which are programmed somewhat like regular computers but just with an astonishingly high number of threads.
This is the topic of my research, and I intend to publish quantitative measurements backing up these assertions before long. Early results look promising.
comment 4y ago · link · parent
Other than that, I do recommend the immediate mode GUI approach if you're writing everything yourself, as it's the lowest overall system complexity of all the approaches. It has a number of drawbacks, and things don't abstract/compose as easily as a standard object-oriented retained, or a newer React/SwiftUI approach, but exposing the raw parts has its upsides.
comment 4y ago · link · parent
ETA: If you're asking for more "straight news" types of sources, https://www.washingtonpost.com/politics/2019/03/22/iraq-war-... is a pretty neutral and objective retrospective, relying heavily on a Senate Intelligence Committee report that was approved on a bipartisan basis.
comment 4y ago · link · parent
I think this also informs recent academic work on RISC-V based GPU work such as RV64X. These are mostly a lot of generic cores with just a little graphics hardware added. The results are not yet compelling compared with shipping GPUs, but I think it's a promising approach.
[1]: https://research.nvidia.com/publication/high-performance-sof...
comment 4y ago · link · parent
comment 4y ago · link · parent
Also as pointed out elsethread, now that buffer device address is starting to land, the friction to compile pointer-intense C++ code should decrease even more. These are exciting times!
[1]: https://github.com/seanbaxter/shaders#approaching-circle-sha...
comment 4y ago · link · parent
CUDA is the Nvidia GPU compute infrastructure and runtime. The native language is a variant of C++, but there are lots of ways to use CUDA from Python (very popular in the machine learning world), Julia, etc. It is an extremely mature and polished way to get access to high performance compute. The biggest downside is that it's Nvidia proprietary.
OpenCL is the older non-Nvidia standard infrastructure for GPU compute. It's languishing though. It is traditionally programmed in OpenCL C, but it does support other languages such as SYCL (another C++ dialect, similar in scope to CUDA C++).
HLSL is similar in that it's a language for programming GPU code, also derived from C (with some C++ sprinkled in), but it's different than CUDA and OpenCL in that it's primarily for graphics applications rather than general purpose compute. The line blurs a bit with the concept of "compute shader," which can be seen as a cut-down CUDA or OpenCL that runs inside the GPU graphics API. Compute shaders are becoming more powerful in each generation. That said, HLSL is overwhelmingly popular for game development, because the tools are so good.
This stuff is confusing. I haven't even touched on the different intermediate representations and the tools for converting between the different languages, of which there is an increasingly dense matrix.
comment 4y ago · link · parent
I also know a little about Covid (having a minor in molecular and cell biology, and obsessively consuming resources like TWiV for a while), and the median amateur virologist comment here is just a howler. Occasionally you'll have people who really know what they're talking about comment, but it usually gets drowned out.
The key, then, as always, is to read everything critically. Then there's some real insight to be gained here.
comment 4y ago · link · parent
More seriously, yes, if you were starting a browser completely from scratch, this would probably be a good approach. There are some subtleties, but probably nothing that couldn't be solved with some elbow grease.
If anyone is seriously interested in exploring this direction, one thing that would be very interesting is a port of piet-gpu to run on top of WebGPU (it's currently running on Vulkan, Metal, and DX12). I've done quite a bit of pre-work to understand what would be involved, but don't personally have the bandwidth to code up the WebGPU port. I would be more than happy to work with somebody who does.
comment 4y ago · link · parent
I think there's potential for interesting things in the future. There's nothing inherently preventing a more latency-optimized GPU implementation, and I personally would love to see that for a number of reasons. That would unlock vastly more computational power for audio applications.
There's also machine learning, of course. You'll definitely be seeing (and hearing) more of that in the future.
comment 4y ago · link · parent
That said, there are some really nice learning resources for Vulkan as well, so if you're motivated and determined, it's also not a bad way to learn modern GPU.
comment 4y ago · link · parent
WebGPU is accessible enough maybe you should try it! You'll learn a lot either way, and it can be fun.
comment 4y ago · link · parent
comment 4y ago · link · parent
Another way of saying this is historian John M. Barry's quote, "when you mix politics and science, you get politics," also famously cited by Peter Daszak.