mcyoung

https://mcyoung.xyz/ (RSS)
visit blog
Nobody Gets Fired for Picking JSON, but Maybe They Should?
10 Dec 2024 | original ↗

JSON is extremely popular but deeply flawed. This article discusses the details of JSON’s design, how it’s used (and misused), and how seemingly helpful “human readability” features cause headaches instead. Crucially, you rarely find JSON-based tools (except dedicated tools like jq) that can safely handle arbitrary JSON documents without a...

The Rust Calling Convention We Deserve
17 Apr 2024 | original ↗

I will often say that the so-called “C ABI” is a very bad one, and a relatively unimaginative one when it comes to passing complicated types effectively. A lot of people ask me “ok, what would you use instead”, and I just point them to the Go register ABI, but it seems most people have trouble filling in the gaps of what I mean. This article...

Designing a SIMD Algorithm from Scratch
27 Nov 2023 | original ↗

Another explainer on a fun, esoteric topic: optimizing code with SIMD (single instruction multiple data, also sometimes called vectorization). Designing a good, fast, portable SIMD algorithm is not a simple matter and requires thinking a little bit like a circuit designer. Here’s the mandatory performance benchmark graph to catch your eye. ...

What is a Matrix? A Miserable Pile of Coefficients!
29 Sept 2023 | original ↗

Linear algebra is undoubtedly the most useful field in all of algebra. It finds applications in all kinds of science and engineering, like quantum mechanics, graphics programming, and machine learning. It is the “most well-behaved” algebraic theory, in that other abstract algebra topics often try to approximate linear algebra, when possible. For...

I Wrote A String Type
9 Aug 2023 | original ↗

I write compilers for fun. I can’t help it. Consequently, I also write a lot of parsers. In systems programming, it’s usually a good idea to try to share memory rather than reuse it, so as such my AST types tend to look like this. pub enum Expr'src> { Int(u32) Ident(&'src str), // ... }Rust Whenever we parse an identifier, rather than copy its...

A Gentle Introduction to LLVM IR
1 Aug 2023 | original ↗

The other day, I saw this tweet. In it, Andrew Gallant argues that reaching for LLVM IR, instead of assembly, is a useful tool for someone working on performance. Unfortunately, learning material on LLVM is usually aimed at compiler engineers, not generalist working programmers. Now, I’m a compiler engineer, so my answer is of course you should...

Single Abstract Method Traits
11 May 2023 | original ↗

Rust and C++ both have very similar operational semantics for their “anonymous function” expressions (they call them “closures” and “lambdas” respectively; I will use these interchangably). Here’s what those expressions look like. auto square = [](int x) { return x * x; }C++ let square = |x: i32| x * x;Rust The type of square in both versions is...

Better Trait Resolution in Rust
4 Apr 2023 | original ↗

Traits are the core of polymorphism in Rust. Let’s review: trait Stringer { fn string(&self) -> String; } impl Stringer for i32 { fn string(&self) -> String { format!("{self}") } } // Prints `42`. println!("{}", 42.string());godboltRust Notice that we call the trait method Stringer::string directly on the value in question. This means that traits...

Atomicless Concurrency
29 Mar 2023 | original ↗

Let’s say we’re building an allocator. Good allocators need to serve many threads simultaneously, and as such any lock they take is going to be highly contended. One way to work around this, pioneered by TCMalloc, is to have thread-local caches of blocks (hence, the “TC” - thread cached). Unfortunately threads can be ephemeral, so book-keeping...

3Hz Computer, Hold the Transistors
24 Jul 2022 | original ↗

I’m not really one to brag publicly about expensive toys, but a few weeks ago I managed to get one that’s really something special. It is a Curta Type II, a mechanical digital1 calculator manufactured in Liechtenstein between the 50s and 70s, before solid-state calculators killed them and the likes of slide-rules. I have wanted one since I was a...

std::tuple the Hard Way
13 Jul 2022 | original ↗

Let’s talk about C++ templates. C++ is famous for relegating important functionality often built into the language to its standard library1. C++11 added a number of very useful class templates intended to make generic programming easier. By far the most complicated is std::tuple<>, which is literally just a tuple. It turns out that implementing...

The Alkyne GC
7 Jun 2022 | original ↗

Alkyne is a scripting language I built a couple of years ago for generating configuration blobs. Its interpreter is a naive AST walker1 that uses ARC2 for memory management, so it’s pretty slow, and I’ve been gradually writing a new evaluation engine for it. This post isn’t about Alkyne itself, that’s for another day. For now, I’d like to write...

Move Constructors Revisited
19 Dec 2021 | original ↗

Almost a year ago I developed the moveit Rust library, which provides primitives for expressing something like C++’s T&& and move constructors while retaining Rust’s so-called “destructive move property”: moving a value transfers ownership, rather than doing a funny copy. In an earlier blogpost I described the theory behind this library and some...

Understanding Assembly Part I: RISC-V
29 Nov 2021 | original ↗

A Turing tarpit is a programming language that is Turing-complete but very painful to accomplish anything in. One particularly notable tarpit is Brainfuck, which has a reputation among beginner and intermediate programmers as being unapproachable and only accessible to the most elite programmers hence the name, as Wikipedia puts it: The...

Everything You Never Wanted To Know About Linker Script
1 Jun 2021 | original ↗

Low level software usually has lots of .cc or .rs files. Even lower-level software, like your cryptography library, probably has .S containing assembly, my least favorite language for code review. The lowest level software out there, firmware, kernels, and drivers, have one third file type to feed into the toolchain: an .ld file, a “linker...

The Taxonomy of Pointers
24 May 2021 | original ↗

Writing unsafe in Rust usually involves manual management of memory. Although, ideally, we’d like to exclusively use references for this, sometimes the constraints they apply are too strong. This post is a guide on those constraints and how to weaken them for correctness. “Unmanaged” languages, like C++ and Rust, provide pointer types for...

Move Constructors in Rust: Is it possible?
26 Apr 2021 | original ↗

I’ve been told I need to write this idea down – I figure this one’s a good enough excuse to start one of them programming blogs. TL;DR You can move-constructors the Rust! It requires a few macros but isn’t much more outlandish than the async pinning state of the art. A prototype of this idea is implemented in my moveit crate. The Interop Problem...

↑ These items are from RSS. Visit the blog itself at https://mcyoung.xyz/ to find everything else and to appreciate author's digital home.