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

Shameless self-promotion. There's a high performance C++ (with neon simd acceleration) implementation at [0]. Note, this also compiles cleanly to wasm and runs in the browser (see the "webaudio" branch). This code is also the basis of the reasonably popular free "dexed" vst. Some of my analysis of the DX7 is on the associated wiki as well.

Not to take anything away from the original posting, but if performance is a goal, this may be interesting.

[0]: https://github.com/google/music-synthesizer-for-android

comment 9y ago · link · parent

I've spent a fair amount of time promoting xi-editor, most notably presenting it at RustConf last year. I've also written a bunch of "rope science" posts about fancy algorithms and data structures for text manipulation, which got attention on HN and elsewhere. I've been more quiet in recent months, but am gearing up for another major wave of community outreach soon.

comment 9y ago · link · parent

One of the greatest strengths of the Web platform is "view source," the ability to start diving into the code any time you find yourself wondering "how did they achieve that?" So a major criticism of WASM is the erosion of that tradition.

However, I suspect that, by volume, most of the WASM code out there is going to be built from open source components, with a little customization sprinkled on top. It takes a little more detective work to find these sources and read them, but I think it's just as worthwhile as in the plain HTML days. Perhaps we could converge on tools and practices that would make it easier to discover the sources from which WASM artifacts were built.

comment 9y ago · link · parent

There's a really good technique for getting rid of the wormy or snake-like textures in Floyd-Steinberg: add another term to the threshold proportional to (some monotonic function of) the distance to the nearest preceding dot. This tends to make the dots very nicely spaced. These ideas were, among other places, used in Gutenprint.

A bit of description, and ancient but working GPL'ed code here: http://www.levien.com/artofcode/eventone/

A paper containing the basic output-dependent feedback idea: http://levien.com/output_dependent_feedback.pdf

comment 9y ago · link · parent

Slashdot was one of the main inspirations for Advogato. One clue in support of this is that the codebase was called "mod_virgule". The trust metrics were designed to be a more sophisticated moderation system than what Slashdot did, but in retrospect I'm not sure it actually worked that much better; Advogato never reached a mass audience and to the extent it had higher quality posts it was probably due to a smaller and more focused community.

I still have my slashdot account (number 3148), but rarely use it. I can well imagine the "complicated feelings" that Rob has, and wanted to add my voice to the many saying that Slashdot was an important Internet space.

comment 9y ago · link · parent

That idea works when the page is swapped in, but I don't think you're accounting for the case where the only copy of the contents is in the file that's backing the mapped region.

comment 9y ago · link · parent

I did a little digging, and don't think so. Being able to access a readonly snapshot is a property of the filesystem, it's a guarantee that if you overwrite file contents, the original data is still available. With btrfs and friends, you could create a "reflink", but these filesystems are not in very widespread use, and it's also not clear to me that it's an overall performance win.

comment 9y ago · link · parent

My reading of the man page[0] is the opposite; your changes won't be reflected to the file, but "It is unspecified whether changes made to the file after the mmap() call are visible in the mapped region."

I'd love to see the other direction. One approach that I think is worth exploring is when the file contents correspond to a git hash that the editor has access to. In fact, there is a pretty relationship between "deltas" and git commits, and this could possibly be exploited usefully.

[0]: http://man7.org/linux/man-pages/man2/mmap.2.html

comment 9y ago · link · parent

I use ropes in xi editor. I did not find the argument against ropes convincing. Yes, they're not trivial to implement, but in a proper programming language you're not dealing with the data structure directly, you're always going through the interface, so you get the logic right once in the rope library implementation and then forget about it.

In a low-level design, your editing operations would be poking at the data structure directly. There, the simplicity of a gap buffer is a pretty big win. I agree in this environment ropes are too complicated. However, I don't see any good reason to architect a text editor in this way. Use abstractions.

The linked article contains a factual error, the referenced Crowley paper does not consider ropes. Thus it cannot be used in support of the argument that piece tables outperform ropes.

There's one other important concern with piece tables I didn't see addressed. It depends on the file contents on disk not changing. If your file system supported locking or the ability to get a read-only snapshot, this would be fine, but in practice most don't. It's very common, say, to checkout a different git branch while the file is open in the editor. Thus, the editor must store its own copy to avoid corruption. In the long term, I would like to see this solved by offering read-only access to files, but that's a deeper change that can be made piecewise.

comment 9y ago · link · parent

Apologies if this is a derail, but how does DirectComposition compare to IDXGISwapChain1::Present1 for high performance scrolling and things like blinking a cursor with minimal energy usage? I was looking at the latter for the Windows port of xi-editor, and unaware of the former. I'm less concerned with fancy graphics effects, but perhaps if they're available at low cost I would consider using them.

I'm also looking to optimize smoothness on window resize, which I've noticed to be pretty janky in many applications.

comment 9y ago · link · parent

This is true, and now there's public documentation that explains a little more of the rationale: https://opensource.google.com/docs/thirdparty/licenses/#wtfp...

comment 9y ago · link · parent

1. This is going to depend a lot on the app; doing an actual DAW is going to require some pretty heavy processing. It also depends on the performance goal. Truly pro audio would be a 10ms end-to-end latency, which is extremely unforgiving.

2. Some form of WebWorker is obviously where we're going. But does postMessage() have the potential to cause delay in the worker that receives it? (There are ways to solve this but it requires some pretty heavy engineering)

comment 9y ago · link · parent

I think things will get a lot better when the underlying enabling technology is in good shape. The audio engine needs to be running in a real-time thread, with all communication with the rest of the world in nonblocking IO. There are lots of ways to do this, but one appealing path is to expose threading and atomics in wasm; then the techniques can be used for lots of things, not just audio. Another possibility is to implement Worker.postMessage() in a nonblocking way. None of this is easy, and will take time.

If we had gone with the Audio Data API, it wouldn't have been satisfying, because the web platform's compute engine simply could not meet the requirement of reliably delivering audio samples on schedule. Fortunately, that is in the process of changing.

Given these constraints, the complexity of building a signal processing graph (with the signal path happening entirely in native code) is justified, if those signal processing units are actually useful. I don't think we've seen the evidence for that.

I'd personally be happy with a much simpler approach based on running wasm in a real-time thread, and removing (or at least deprecating) the in-built behavior. It's very hard to specify the behavior of something like DynamicsCompressorNode precisely enough that people can count on consistent behavior across browsers. To me, that's a sign perhaps it shouldn't be in the spec.

Disclaimer: I've worked on some of this stuff, and have been playing with a port of my DX7 emulator to emscripten. Opinions are my own and not that of my employer.

comment 9y ago · link · parent

You don't need to convince me, but you'd be surprised some of the pushback I've gotten[0].

I don't have a lot of experience with GIS, but you're telling me that a linear scan through all the features on a map isn't good enough? :)

[0] https://news.ycombinator.com/item?id=14129543

comment 9y ago · link · parent

Looks pretty neat, thanks for the link. From a quick look, it seems like the performance characteristics will be pretty similar to a xi-style rope (it seems extremely unlikely to me that the time spent finding the child is significant, so the radix trick can't save much time), and it's a bit more complex. That said, I do expect it to perform nicely for read-only access to large documents, which is definitely an important use case.

It would make a fun project for somebody to implement it and compare the performance. I'd certainly take the PR for it if the performance was better :)

[edit: followup] The rope implementation in xi has an additional heuristic that tries not to split lines across leaf boundaries (ie most leaves should end in a newline). It also has a hard constraint of not splitting a unicode codepoint. Thus, leaves and subtrees would have an unpredictable number of elements (as opposed to being a clean power of two when full) and I think that pretty much invalidates using the radix to select the child.

comment 9y ago · link · parent

If you really want to solve the problem, use a rope. The advantage of gap buffers is simplicity (accounting for the gap is a simple compare with a couple of numbers). Ropes are definitely more complicated, but they have massive advantages in worst-case complexity (most edit and query operations have O(log n) cost).

comment 9y ago · link · parent

The first part of the article is true; gap buffers are not a data structure particularly optimized for multiple cursor edits. The conclusion is ridiculous. Of course you can provoke noticeable slowdown by doing an edit with thousands of cursors, but most people are doing small edits to small files, so the cost of the memmove operations is probably in the microseconds per cursor range. If multiple cursors feel intuitive to use and gives immediate visual feedback, why shouldn't people use them?

I say this as someone who has chosen a more sophisticated data structure (ropes) in the editor I'm working on.

comment 9y ago · link · parent

It's fine for a monospaced font to contain an "fi" ligature (to represent Unicode U+FB01), but it absolutely should not contain a "liga" feature to form it from "f" and "i". I'd personally not even create a "dlig" (discretionary ligature).

Not surprising to see this, because the rules are quite different for non-monospaced fonts (almost all fonts should have a liga feature for fi, and all modern text layout engines should respect it).

Source: I've worked in this space.

comment 9y ago · link · parent

Oops, yes, you're correct, I was typing from memory and didn't double-check.

And yes, the Taylor series is pretty good but you can usually squeeze a bit more accuracy-over-range by, eg, using an optimizer for the coefficients. Also, note that in your notebook you have x^3/5 but x^3/6 is probably what you wanted.

comment 9y ago · link · parent

A bit OT but my favorite way to approximate tanh is to do g(f(x)) where f(x) is an odd polynomial and g(x) is 1/sqrt(1 + x^2). The recip sqrt can be computed very quickly using Newton approximation, and many SIMD instructions have an instruction for it. Highly recommended for audio applications.

comment 9y ago · link · parent

Also not C, but closer: https://docs.rs/xi-rope/0.2.0/xi_rope/

This is a rope implementation in Rust with lots of features useful for text editors.

comment 9y ago · link · parent

Graph isomorphism is a known NP-hard problem, but the vast majority of subgraphs in programs are reducible, so I expect that aligning two control flow graphs admits a good heuristic solution.

comment 9y ago · link · parent

Tada! That's very close to what I had in mind. The only difference: you can fizz on 4924, buzz on 4210, none on 34cb, then always \n. Also, you have 3 ops to calculate the rotation, and that can be replaced by (0x8001 * x) >> 1 (for uint16_t x), but with tweaking of the masks because it's rotating right.

Congrats!

comment 9y ago · link · parent

Good candidate for most evil use of the assumption that char is signed. Incidentally, that's not going to be true on arm[0].

[0]: http://blog.cdleary.com/2012/11/arm-chars-are-unsigned-by-de...

comment 9y ago · link · parent

Indeed, llvm is smart enough not to use a DIV instruction for modulo of a constant.

Turns out you can compute x%3 == 0 with even fewer steps, it's (x*0xaaaaaaaab) < 0x55555556 (assuming wrapping unsigned 32 bit arithmetic).

comment 9y ago · link · parent

You're absolutely on the right track with a (wrapping) multiply and a shift right, but the constants aren't quite right.

comment 9y ago · link · parent

I see your point regarding pure cycle counting, but as I posed the puzzle it's still open :)

comment 9y ago · link · parent

I see your points; maybe I need to work on the storytelling in posing the puzzle. I do stand by the principle that avoiding branch mispredicts is worthwhile if you can replace the branch with 1 or 2 logic/arith C operations. In any case, the point of the puzzle is how to get a not-quite-trivial result from extremely efficient sequence of pure logic/arith operations.

comment 9y ago · link · parent

This is true, and I've thought about it a bit. If you were really optimizing, then maybe the goal would be stated as putting the completed answer into a memory buffer. But for now, shave as many nanoseconds as you can from the logic and pretend we don't have to worry about printing.

comment 9y ago · link · parent

I should have stated extra constraints; you're not allowed to use either additional memory (memory accesses are slow) or an if statement to update your state (branch mispredicts are slow). Yes, these are arbitrary (and I know the total time would be dominated by the cost of printf), but the point is to shave nanoseconds. Also, you've still got the duplication of strings.
1
5960616263