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

I've just recently switched over to it for my day to day work. Admittedly there are rough edges, but I think it's fair to call it viable for sufficiently small values of viable. I expect to do a major push later in the year to polish it to the point of being really viable.

comment 9y ago · link · parent

Apologies if this is somewhat off-topic for the thread, but I suspect this will be a fun puzzle for fans of low-level optimization. The theme is "optimized fizzbuzz".

The classic fizzbuzz will use %3 and %5 operations to test divisibility. As we know from the same source as OP, these are horrifically slow. In addition, the usual approach to fizzbuzz has an annoying duplication, either of the strings or of the predicates.

So, the challenge is, write an optimized fizzbuzz with the following properties: the state for the divisibility testing is a function with a period of 15, which can be calculated in 2 C operations. There are 3 tests for printing, each of the form 'if (...) printf("...");' where each if test is one C operation.

Good luck and have fun!

comment 9y ago · link · parent

1. If you're using an Electron-based editor, I imagine you might not be entirely happy with performance. I can fix that. 2. Yes, have looked at Kakoune, and even have some plans to emulate its keybindings. It's an interesting project. 3. I'm not sure novelty is the main thing people need. I think we pretty well understand what people need, and there's something to be said for just doing a good job delivering it.

comment 9y ago · link · parent

The thoughts on commercialization are a hypothetical. As I said in my original comment, it's off the table (though I gave other reasons than being employed by Google). I'm just saying that if there were a revenue stream, then I'd be incentivized very differently (and more in line with what users need) than purely as a labor-of-love open source project.

And yes, if there were a good reason to, Google could bring considerable resources (including marketing) to bear.

comment 9y ago · link · parent

Right, I didn't write clearly. After a couple months of pushing to a 1.0, I'd expect maybe a few thousand users (this seems reasonable to me because it's the number of github stars). That's enough though that I'd need to start worrying about the product rather than just the technology, but that could all be done part-time.

My estimate of a million users is what might happen after another year or two of building out the whole vision, and with organic growth from numerous sub-communities (for example, I'd expect Rust users to be quicker to adopt it because it's in Rust). At that point, it's clear that the project would need at least a full time person to be its maintainer. And I don't see how to sustain that.

Thanks for emphasizing the focus on marketing; it is indeed a knob I can turn.

comment 9y ago · link · parent

A) I'll toss out 1M because you asked for a number.

B) Because if I build out my full ambition, it would be better by most objective metrics (speed, features, integration with IDE-like capabilities) than all the free editors out there, and I think there is a real demand for a better editor.

I know what you mean about the struggle for traction. It is of course possible I'm massively mis-estimating the potential userbase.

comment 9y ago · link · parent

I have a largish open-source portfolio, including a markdown parser, a regex engine, some music synthesis, and some more researchy stuff like a font renderer and a prototype of concurrent text editing using CRDT's. I'm lucky to be working at Google where I get paid 20% time to work on this, but the motivation is definitely not money.

The biggest item in my portfolio is xi-editor, and I confess I'm wrestling with some of the questions raised in this thread. I think it has the potential to be a serious player in the editor space, with extremely high performance goals (including fast startup and low RAM usage) yet a modern feel. It also has a great little open-source community around it who have been contributing significant features.

Yet it's at the point where it's _almost_ done enough to use for day-to-day editing, and I'm hesitating a bit before pushing it over the line. I think I'm scared of having lots of users. It's also the case that I'm very interested in the engine and the core of the UX, but the complete product needs a plugin ecosystem and along with that ways to discover, upgrade, and curate the plugins (including making sure they are trustworthy, lately a fairly significant concern). That's potentially a huge amount of work, and it doesn't really line up with my interests.

I'm wondering if it's possible to focus on the parts I care about and try to foster the community to take care of the rest, but I'm not quite sure how that would work.

If this were a business and I had some way of making a few coins from every user, then my incentives would be lined up to make the best overall product possible, including the less fun parts. But that's off the table; among other things, there are a number of good free editors out there, and the niche for a better but non-free editor is also well occupied.

Maybe the HN crowd has some ideas?

comment 9y ago · link · parent

The Friendly C idea seems to be basically dead. For an update of what Regehr is pursuing now, see https://blog.regehr.org/archives/1520 (Undefined Behavior in 2017).

comment 9y ago · link · parent

This is a really good question. Each language adopts its own philosophical stance on the matter. Java is an excellent example of a language that tries to minimize undefined behavior, as much as C maximizes it. Even in the case of data races, the range of machine behavior is quite constrained (it can't break type safety, for example). This approach has some cost in performance, but Java is still performant. We don't need to worry much about programs breaking as Java compilers optimize more aggressively, although in earlier days there were sloppy programs that depended on the specific behavior of the specific JVM they were written on (see Cliff Click's writings for more on this).

Probably the majority of languages are philosophically the same as Go; in single-threaded operation there's not much undefined behavior, but once you go multithreaded and have a data race, all bets are off. The "memory model" document is not very precise, but mostly states that if you avoid data races, things will be ok.

All languages with FFI to C, of course, inherit C's approach to undefined behavior through that mechanism.

comment 9y ago · link · parent

This is excellent and I have no idea why the 5 or so previous submissions failed to gain any traction. The topic is fascinating, and the style of presentation (video coordinated with interactive 2D and 3D animated models) is absolutely of interest to hackers.

comment 9y ago · link · parent

This has been discussed quite a bit, and there are very good reasons why not[0]. But I suppose things can always change.

[0]: https://internals.rust-lang.org/t/crates-io-package-policies...

comment 9y ago · link · parent

Pretty sure that code gives the wrong answer for a = 0, b = 1 << 63 (assuming the goal is equality represented as 0 or 1).

comment 9y ago · link · parent

From Google's official opensource documentation on IARC[0]: We don’t approve every project submitted through this process, but historically we’ve been able to rapidly approve the vast majority of them.

I personally have had one IARC approved and one denied (and something like a dozen opensource launches), but from what I've seen, the above statement is accurate.

[0] https://opensource.google.com/docs/iarc/

comment 9y ago · link · parent

That makes it especially impressive that he used React and other recent Web technologies to build the site.

(It's been around a while but this is a rewrite and looks like a pretty massive update)

comment 9y ago · link · parent

Confirmed. The title statement is wrong. I think the moral of _that_ story is that not even renowned experts can reliably get bash right.

comment 9y ago · link · parent

I wouldn't say category here, to be precise it's the same cofunctor over the initial algebra.

comment 9y ago · link · parent

I have no idea what you mean about "intentionally destroying" line info. The info is right there, and there's a perfectly nice interface (Cursor) for getting at it; no real difference between calling next() on a Cursor object and doing line_index++.

Besides, what's a "line"? Is it a source line, or a visual line after wrapping? In an editor, you care deeply about both, depending on what exactly you're doing. With an array of lines, you pick one for the representation, and when you want the other one, it's quite painful. With ropes, no problem at all, just two different Cursor objects into the same rope.

I agree, other decisions besides buffer representation are important, and I'm doing my best to get those right too.

comment 9y ago · link · parent

I used an array of lines in gzilla[0]. It's not bad, but it _is_ exporting details of the representation up to clients, which gets worse once you add some hierarchy. To me, the nice thing about ropes is that they appear to the client as just a string, with some fancy added methods such as creating a cursor that can advance to the next or previous line efficiently. Of course, to make this work, you need a good programming language; an implementation of ropes in C would be painful.

As I said elsewhere on the thread, the good thing about ropes is their worst case performance. Super-long line? Rope still efficient. 10 million line file? Rope still efficient. Massive sequence of edits relative to the pristine file? Rope still efficient. It's pretty easy to write code which works well in the common cases but then degrades when things get interesting. I'm not going to apologize for caring about that.

[0] http://www.levien.com/free/gzilla-tour.html

comment 9y ago · link · parent

It would be possible. I'm thinking of adding "pack/unpack" operations to the Leaf data structure, but it's more motivated by getting a varint encoding for line breaks; right now each break is a 64 bit integer (on 64 bit builds), so if you have file consisting of empty lines, the corresponding line break data structure is 8 times bigger than the text. With the varint encoding I have in mind, it would be bounded at 1/4.

That said, I'm very skeptical that lz4 on text would be worth it.

comment 9y ago · link · parent

The true strength of the rope data structure its performance in worst case conditions. Even after a huge series of edits, it recombines leaves and rebalances the tree so it's almost as efficient as when it's loaded freshly. It's not like a piece table, which is amazingly efficient at first and then fragments.

[The actual analysis is much more subtle, as the tree invariants are a minimum and maximum number of children for non-root non-leaf nodes, and a minimum and maximum leaf size. When freshly loaded, the code is careful to maximally pack both, and after extensive editing the distribution will be more varied. However, it's still rigorously O(log n), so it ends up being a small constant factor. Might be worth doing some empirical performance testing.]

comment 9y ago · link · parent

It's not comprehensive yet, but at least you can navigate the API at https://docs.rs/xi-rope/0.2.0/xi_rope/

comment 9y ago · link · parent

Hi Jon! Great to see you here. Much of what I wrote is speculative, especially paren matching based on monoids. What actually went into xi editor is much more conservative. I didn't actually intend this to be posted to HN, but am not too surprised it did.

As to being a young person, I don't know if you remember, but I was already of drinking age when you and me and Adam Sah hung out a bit and talked about the "rush" language.

I admit to being excited, but because I think "modern" editors really are too bloated and slow and it causes a thousand paper cuts throughout the day, and I think that can be fixed.

comment 9y ago · link · parent

An example of the linear-interpolated lookup table approach using fixed-point math is the sine generation[0] in my music synthesizer. It generates a table of 1024 entries, then lerps between those. This gives you precision beyond the least perceptible audio error, and is pretty fast.

When I first wrote that code, I was targeting 32 bit ARM, with possibly very weak floating point units. These days, on the types of chips you'd see in phones (or computers in the $9-$40 range like rpi 3), the floating point calculation is _so_ fast (especially with simd) that the cost of the memory lookup starts dominating. So, the NEON implementation computes 4 sin values in a gulp, using a floating point polynomial approximation about the same precision as above[1].

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

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

comment 9y ago · link · parent

Thank you for sharing the story of your friend. It brought tears to my eyes.

Feeling guilt about not being able to do more is a natural consequence of suicide. But it sounds like you were there for him, able to really listen. Think of how many people struggling with these sorts of problems don't have that.

comment 9y ago · link · parent

The use of math in economics is much like the use of Newtonian mechanics to understand elementary particle interactions at the horizons of black holes.

comment 9y ago · link · parent

I think that's only half-useful, at best. If all your access to atomics happened to be mediated by, say, __atomic_cmpxchg, then modeling that as (say) atomic_compare_exchange_strong would give you confidence in the implementation. The problem is that pre-memory model code is also likely to check the current state of the atomic through a raw pointer load instead of anything like atomic_load (which generally has no counterpart in pre-memory model synchronization libraries). So, analyzing that code through the lens of C11 tells you little more than that it's undefined behavior.

Like most undefined behavior, it can work in practice. Probably. Most of the time. If you stick to using older compilers.

comment 9y ago · link · parent

These are theoretical concepts. If there's a bound on the slowdown, it's lock-free. If there's no bound, it's obstruction free.

These theoretical concepts might or might not be that relevant for real-world applications. For example, in real-time audio (the main domain of interest to me for lock-free techniques), what you really care about is that the audio rendering thread will produce one buffer worth of sound before the hardware finishes outputting the previous buffer. This sounds like a match for "wait-free", but it depends on the details. If the non-audio thread can cause a 100x slowdown (but no more) that would technically be wait-free, but you'd miss your buffer, and so it's not acceptable. Another system might use mutexes, but be carefully engineered so that the locks are never held for more than 100µs (say, using locks designed to handle priority inversion), and thus reliably meet the needs even if it's not technically anything like lock-free.

But, as with anything, these concepts are useful tools, and I _love_ lock-free algorithms for audio.

comment 9y ago · link · parent

Absolutely. The Java ecosystem deserves a huge amount of credit for putting lock-free programming on a theoretically sound basis, and it's informative how long it took to get it right.

But none of that had a serious effect on C and C++ practice until C++ started formalizing the memory model. Even today, we still have to deal with a lot of legacy code that uses pre-memory model primitives such as __sync_synchronize, __atomic_cmpxchg, InterlockedCompareExchange, etc. I'd like to see all that stuff go sooner rather than later. In my opinion, the original article is not helping, as it shows C code that does reads and writes through pointers, expecting them to behave as atomic operations.

comment 9y ago · link · parent

I stand corrected, thanks! I had the feeling that the ABA problem affected a lot of the earlier lock-free algorithms, but didn't know the understanding of it went that far back.
1
5960616263