HNHacker News
TopNewBestAskShowJobs

matklad

1,382 karma · joined February 17, 2014

https://github.com/matklad
submissionscomments
matklad··on Font-size-adjust Is Useful
To clarify, "specify @font-face inline" meant to say that the font's URL should be in the `head`, not the actual font bytes. The linked page includes `<link href="/fonts/GeistVF.woff2" rel="preload" type="font/woff2" as="font" crossorigin="">` in the `head`, which is another (probably better) way to achieve "font URL in the head" outcome.

But I must say I don't agree with `font-display: optional` advice. It indeed maximize the LCP and CLS metrics, but it does that to the extent that the results become detrimental to the user experience. Like, if I open that link in a private window, and then hit refresh, the layout shifts, because I don't have their custom font on the first load, but do have it on the second one. This doesn't make sense! Do you want me to see your custom font or not?

I would say that if you _really_ care about the page being ready as fast as possible, you should use `font-style: system-ui`. If you _really_ care about your fonts, you should use `font-display: auto` or `font-display: block` (and, yes, tweak fallback font metrics). If you care about _both_, tough luck, they are inherently in conflict and you need to pick one side. `font-display: optional` let's you formally pass the automated test with flying colors, but doesn't seem to result in actually useful behavior?

matklad··on NIH is cheaper than the wrong dependency
(I work on TigerBeetle)

+100, context is the key thing, both TigerBeetle and rust-analyzer have strong culture of how the things are done, but the _specific_ culture is quite different, because they solve very different problems.

That being said, I _think_ you might be pattern-matching a bit against the usual dependencies good/dependencies bad argument, and the TFA is on a different level. Note the examples of dependencies used: POSIX, ECMA-48, the web platform. These are not libraries, these are systems interfaces!

Dependency on a library is not a big deal --- if it starts to bite, you can just rewrite the code! But dependency on that underlying thing that the library does is usually something that can't be changed, or extremely costly to change. Answering "No" to "is doing X in scope for my software?" is powerful

To refer to the sibling comment, if there's a team whose core business is writing matrix multiplication code, they _can_ use random library #24 for something else, but often, if you apply some software design, you might realize that the product surrounding matrix multiplication _shouldn't_ handle concern #24. It doesn't mean that concern #24 isn't handled by anything at all, rather that we try to find _better_ factoring of the overall system to compartmentalize essential dependencies.

matklad··on RSS Server Side Reader
I used to do frontend development ([1], [2]), now I am more of a database person ([3]), though it mostly is just prompting llvm to generate the right code!

[1] https://github.com/intellij-rust/intellij-rust

[2] https://github.com/rust-analyzer/rust-analyzer

[3] https://github.com/tigerbeetle/tigerbeetle/

matklad··on Jepsen: TigerBeetle 0.16.11
To add to what aphyr says, you generally need three components for generative testing of distributed systems:

1. Some sort of environment, which can run the system. The simplest environment is to spin up a real cluster of machines, but ideally you want something fancier, to improve performance, control over responses of external APIs, determinism, reproducibility, etc. 2. Some sort of load generator, which makes the system in the environment do interesting thing 3. Some sort of auditor, which observes the behavior of the system under load and decides whether the system behaves according to the specification.

Antithesis mostly tackles problem #1, providing a deterministic simulation environment as a virtual machine. The same problem is talked by jepsen (by using real machines, but injecting faults at the OS level), and by TigerBeetle's own VOPR (which is co-designed with the database, and for that reason can run the whole cluster on just a single thread). There there approaches are complimentary and are good at different things.

For this bug, the critical part was #2, #3 --- writing workload verifier and auditor that actually can trigger the bug. Here, it was aphyr's 1600 lines of TigerBeetle-specfic Clojure code that triggred and detected the bug (and then we patched _our_ equivalent to also trigger it. Really, what's buggy here is not the database, but the VOPR. Database having bugs is par of course, you can't just avoid bugs through the sheer force of will. So you need testing strategy that can trigger most bugs, and any bug that slips through is pointing to the deficiency in the workload generator.)

matklad··on Jepsen: TigerBeetle 0.16.11
Oh, important clarification from andrewrk(https://lobste.rs/c/tf6jng), which I totally missed myself: this isn't actually a dereference of uninitialized pointer, it's a defer of a pointer which is explicitly set to a specific, invalid value.
matklad··on Jepsen: TigerBeetle 0.16.11
Note that this works because we have strict serializability. With weaker consistency guarantees, there isn't necessarily a single global consistent timeline.

This is an interesting meta pattern where doing something _harder_ actually simplifies the system.

Another example is that, because we assume that the disk can fail and need to include repair protocol, we get state-synchronization for a lagging replica "for free", because it is precisely the same situation as when the entire disk gets corrupted!

matklad··on Jepsen: TigerBeetle 0.16.11
From the user's perspective, this doesn't matter at all. Zig is implementation detail, what we actually ship is a fully statically linked native executable for the database, and "links only libc" (because thread locals!) .a/.so native "C" library for clients. Nothing will change, for the user, if we decide to rewrite the thing in Rust, or C, or Hare, nothing Zig-specific leaks out.

Form the developer perspective, the big thing is that we don't have any dependencies, so updating compiler for us is just a small amount of work once in a while, and not your typical ecosystem-wide coordination problem. Otherwise, Zig's pretty much "finished" for our use-case, it more or less just works.

matklad··on Jepsen: TigerBeetle 0.16.11
See https://news.ycombinator.com/item?id=44201189. We did have one bug where Rust would've saved our bacon (instead, the bacon was saved by an assertion, so it was just slightly crispy, not charred).

EDIT: But, yeah, totally, if not for TigerStyle, we'd die to nasal demons!

matklad··on Jepsen: TigerBeetle 0.16.11
Just to clarify, our _model_ totally assumes bit/byte error! It's just that our fuzzer was buggy and wasn't actually exercising those faults!
matklad··on Jepsen: TigerBeetle 0.16.11
Note that that's a bug in the client, in the Zig-java FFI code, which is inherently unsafe. We'd likely made an a similar bug in Rust.

Which is, yeah, one of the bigger technical challenges for us --- we ship language-native libraries for Go,node,Java,C#,Python and Rust, and, like in the Tolstoi novel, each one is peculiar in its own way. What's worse, they aren't directly covered by our deterministic simulator. That's one of the major reasons why we invest in full-system simulation with jepsen, antithesis and vortex (https://tigerbeetle.com/blog/2025-02-13-a-descent-into-the-v...). We are also toying with the idea of generating _more_ of that code, so there's less room for human error. Maybe one day we'll even do fully native client (eg, pure Java, pure Go), but we are not there yet.

One super-specific in-progress thing is that, at the moment, the _bulk_ of the client testing is duplicated per client, and also the _bulk_ of the testing is example-based. Building simulator/workload is a lot of work, and duplicating it for each client is unreasonable. What we want to do here is to use multi-process architecture, where there's a single Zig process that generates the workloads and generates interesting sequences of commands for clients, and than in each client we implement just a tiny "interpreter" for workload language, getting a test suite for free. This is still WIP though!

Regarding the broader memory safety issue in the database. We did have a couple of memory safety bugs, which were caught early in testing. We did have one very bad aliasing bug, which would have been totally prevented by Rust, which slipped through the bulk of our testing and into the release (it was caught in testing _after_ it was introduced): https://github.com/tigerbeetle/tigerbeetle/pull/2774. Notably, while the bug was bad enough to completely mess up our internal data structure, it was immediately caught by an assert down the line, and downgraded from correctness issues to a small availability issues (just restarting the replica would fix it). Curiously, the root cause for that bug was that we over-complicated our code. Long before the actual bug we felt uneasy about the data structure in question, and thought about refactoring it away (which refactor is underway. Hilariously, it looks that just "removing" the thing without any other code changes improves performance!).

So, on balance, yeah, Rust would've prevented a small number of easy bugs, and on gnarly bug, but then the entire thing would have to look completely different, as the architecture of TigerBeetle not at all Rust-friendly. I'd be curious to see someone replicating single-thread io-uring no malloc after startup architecture in Rust! I personally don't know off the top of my head whether that would work or not.

matklad··on Things Zig comptime won't do
I'd flip it over and say that C++ has overloading&SFINAE to enable polymorphism which it otherwise can't express.
matklad··on Things Zig comptime won't do
Yeah, that one Zig can not do, hence "-lite".
matklad··on Things Zig comptime won't do
>I'm not saying it may not have other problems, but that is very novel.

Just to explicitly acknowledge this, it inherits the C++ problem that you don't get type errors inside a function until you call the function and, when that happens, its not always immediately obvious whether the problem is in the caller or in the callee.

matklad··on Things Zig comptime won't do
> Dependent types are types that depend on values.

Like this?

    fn f(comptime x: bool) if (x) u32 else bool {
        return if (x) 0 else false;
    }
matklad··on Things Zig comptime won't do
The thing is, this is not type-level programming, this is term-level programming. That there's no separate language of types is the feature. Functional/imperative is orthogonal. You can imagine functional Zig which writes

    Pair :: type -> type -> type
    let Pair a b = product a b 
This is one half of the innovation, dependent-types lite.

The second half is how every other major feature is expressed _directly_ via comptime/partial evaluation, not even syntax sugar is necessary. Generic, macros, and conditional compilation are the three big ones.

matklad··on Things Zig comptime won't do
>for Zig enthusiasts, the set of features that Zig has appeals to them. Just like enthusiasts of every programming language.

I find it rather amusing that it's a Java and a Rust enthusiast who are extolling Zig approach here! I am not particularly well read with respect to programming languages, but I don't recall many languages which define generic pair as

    fn Pair(A: type, B: type) type {
        return struct { fst: A, snd: B };
    }
The only one that comes to mind is 1ML, and I'd argue that it is also revolutionary.
matklad··on We Designed TigerBeetle's Docs from Scratch
The second one. `git clone` only gets slower with time, so it's important to optimize for it.
matklad··on Use Long Options in Scripts
Was waiting for this comment :P

The API used handles string interpolation correctly: the string literal is parsed at compile time, and the interpolated arguments are never concatenated or escaped, and end up directly as an element of arv array passed to a child. See

https://github.com/tigerbeetle/tigerbeetle/blob/7053ecd2137a...

matklad··on Try to fix it one level deeper
I was not actually aware of the paper, and it is indeed pure gold, thanks for linking it. It is _also_ extremely timely, as with my current project (TigerBeetle), we are exactly at the point of transition from first-principles back-of-the-envelope performance architecture to measurement-driven performance engineering, and all the advice here is directly applicable!
matklad··on LSP: The good, the bad, and the ugly
And

https://rust-analyzer.github.io/blog/2020/07/20/three-archit...

Is a must-read if you are to build your own LSP server!

matklad··on Mimalloc Cigarette: Losing one week of my life catching a memory leak (Rust)
The answer is clear: just don’t have a malloc implementation in your process' address space!
matklad··on How I Use Git Worktrees
* https://github.com/matklad/config/blob/a6ee2271a303fd4e6ea50...

* https://github.com/matklad/config/blob/a6ee2271a303fd4e6ea50...

matklad··on The sad state of property-based testing libraries
Do you have a model problem which is tricky to shrink?

I implemented a stupid simple shrinker for arbitrary, and I’d love to know a specific example where it fails to shrink in a good way:

https://github.com/matklad/arbtest/blob/0191f93846e9f7e38254...

I know at lest two interesting approaches for making that way smarter, but I don’t yet have a problem where my dumb approach isn’t sufficient.

matklad··on Git Things
For comparison, this is how the message looks when wrapped manually:

https://github.com/matklad/repros/commit/7d7dc3e3539e8cc68e5...

(Every time I see someone advocating for _not_ wrapping plain text formats, I can't get an image of a hammerhead shark sitting in front of a 16:9 display out of my mind :-)

matklad··on Git Things
>I don't know of an interface other than email that doesn't wrap them.

Here are some common examples:

1. GitHub's single commit view word-wraps at monitor width, not at a reasonable line length:

https://github.com/matklad/repros/commit/9351f5c91bd1d80dbcc...

The result is completely unreadable.

2. `git log` in a full-screen terminal wraps at window width, not at a readable length.

3. In VS Code in Magit, lines are not wrapped at all by default. It is possible to enable wrapping, but then they are wrapped at the screen edge, not at a readable line length. I _think_ VS Code actually has a setting to visually wrap at column, but I wasn't able to make that work.

Additionally, if you look at that commit message, you'll see that, to properly soft-wrap it, you'll need a markdown parser to recognize an indented bullet list. VS Code actually wraps that list correctly, but I expect very few other tools to do that.

matklad··on The Heart of a Language Server
>The fact that Jetbrains was actually behind rust-analyzer

To clarify, I was not working at JetBrains when I started to work on rust-analyzer, so they are not _directly_ behind. They are very much indirectly behind though, as

- JetBrains was funding a lot of educational projects for students of software engineering, such as myself. - JetBrains generally pioneered modern static analysis based IDEs: https://martinfowler.com/bliki/PostIntelliJ.html - Most of things I've learned about IDEs, I learned at JB, studying their open source tools - I was able to spend a year hacking on rust-analyzer for free due to my savings from the work at JetBrains - And, after those funds run out, I worked part time in the educational department of JB, teaching students algorithms, Python, and Rust

> I suppose there was lots of "support" from the more experienced people, specially regarding the architecture, which I believe is what you're saying made it even possible?

Not really, in a sense that I didn't have a dedicated mentor to check on me on a daily basis, but also such support is not really needed. You are writing a plugin, so the overall architecture is a given, and you just fill in the details. And most of the things you need you can learn from the docs and source code of existing plugins, and that also retroactively explains the overall architecture to you. So, by the time I started hacking on rust-analyzer, the core "throughput-vs-latency" tradeoff was clear to me, and, after taking an extra look at dart-analyzer, roslyn, and Swift libsyntax all pieces fell into place. It's a shame of course that there's no single "IDE book", and you really need to dig into the source and uncover the knowledge, but that's why `https://rust-analyzer.github.io/blog` exists!

>I guess Rust would've been successful (because of its own merits as a language) even if its IDE story was as bad as other new languages normally are (and eventually, because of many people having interest in it, the situation would improve fast), but maybe I'm wrong and the existence of rust-analyzer and RLS before that did actually "cause" the success...

Yeah, it's hard to untangle these! I would say these all were mutually reinforcing: fundamentals of language design screaming "this _could_ be big if it doesn't fail", people getting excited about Rust early on and hacking on the language and associated tooling, the tooling making it pleasant to actually use the language, people getting excited about using Rust to do stuff and increasing the size of the ecosystem (which directly defines the amount of funding available). The bottom turtle is maybe Graydon engineering the best language-design-and-implementation team in the world?

matklad··on The Heart of a Language Server
Yes
matklad··on The Heart of a Language Server
> It took 2 years of work while sponsored by a real business

With a team of 1.5 people. I personally wouldn't call that amount of effort "huge", but adjective definitions may vary. The important bit here is "couple of people over couple of years" is what it takes to get a decent IDE support from zero for a reasonable language, provided that the initial architecture is right.

> A short history of the rust-analyzer can be found

To clarify, I am the original author of that text, rust-analyzer, and IntelliJ Rust. To add a little more details, the reason why rust-analyzer was started in 2017, is that before that I had been working on IntelliJ Rust. By 2017, IntelliJ Rust was already in a good shape! And the success of IntelliJ Rust was the main reason why folks were willing to pay me money for working on rust-analyzer.

IntelliJ Rust was started on the 1st of September in 2015 (before RLS). No one used Rust at that point, not even for blockchain, and then I think it was impossible to predict with high level of confidence that Rust would be big. Even more so, I think both me and my manager at JetBrains were underestimating future Rust success at that time, as we were thinking mostly about relatively niche systems programming market, and didn't see that Rust would be a success as a general-purpose programming language with people doing web stuff in it (obviously, that niche would be occupied by Kotlin!).

But funding one intern to hack on an IDE for obscure language in St. Petersburg was not a significant expense for JetBrains. And, given that the plugin was well received by then nascent Rust community, it made sense to gamble and to just hire the intern to be a full time junior dev.

>So, yeah it takes little effort to get a basic IDE... that's where most languages (e.g. D, Nim) stop... the hard part is to get something that's really good.

This glosses over an important detail: rust-analyzer was playing catch up with RLS, the work on which started roughly a year after IntelliJ Rust, I think in august of 2016. Unlike rust-analyzer, RLS was a real effort by the rust project itself, but it just couldn't be good enough, because the underlying architecture was not suitable for IDEs. Adding more effort to RLS wouldn't have helped, it was necessary to build a different thing.

This I think is a bad equilibrium a lot of IDE efforts can get stuck in --- you really need to apply effort on top of the right architecture to not get stuck, but the knowledge of which architecture is right used to be very obscure.

matklad··on The Heart of a Language Server
>because it managed to get enough people to muster the huge effort that requires.

Not really true on both counts:

- you don't need _that_ many people, if you know what you are doing. For both rust-analyzer and IntelliJ Rust, the headcount was around one-and-a-half people between the first line written and the point where the thing basically works

- the "mustering" only came together after the tools have proven themselves to be successful. _Today_ both rust-analyzer and Rust Rover have dedicated teams working on them, but it is a _consequences_ of the fact that these IDEs work great, not a cause. It was a shoestring budget at the beginning!

Rust is not the easiest language to build an IDE for, but you really don't need a Google-level of effort for that either. What you do absolutely need though, is an _understanding_ of how to build an IDE, and that's very niche knowledge!

matklad··on Push ifs up and fors down
Thanks! You are exactly the target audience for this article! It really is only useful when:

* you already have the intuitive understanding of problems being described

* but you haven’t quite yet verbalized the problem and connected the dots

This clicked for me yesterday, happy that it helped you to articulate what you’ve already knew today!

← PreviousPage 2 of 7Next →