←
Josh Haberman300 posts
Josh Haberman avatar

Josh Haberman

@JoshHaberman

I work on the Protocol Buffers team at Google. I created upb (a small C protobuf implementation) and Bloaty (an ELF/Mach-O/PE/WASM binary size profiler).

◷ Joined May 2011▧ 5 Photos and videos
WalterBright avatar
⟳ Josh Haberman retweeted
WalterBright@WalterBright·18 Dec 2025

This debugging technique should be common knowledge, but I run across it all the time. When an error message is confusing, by far the most practical method to figure it out is to: 1. copy the file to a new file, save the original 2. delete code until the message goes away 3. revert to the previous version that still produced the error 4. goto step 2, and delete something else 5. continue until you have the minimum piece of code that generates the error This usually clears up the understanding of the issue. The D "dustmite" program (created by crackerjack developer Vladimir Panteleev) can do this automatically. Recently, I was handed a program with a baffling error in it. I noticed it was loaded with templates, conditional compilation, irrelevant functions, and complex declarations. Deleting all that fluff out of it led directly to the problem. This is the most powerful debugging technique I know of. I use it all the time.

Josh Haberman avatar
Josh Haberman@JoshHaberman·30 May 2024

I'm getting more and more spam texts these days. I can imagine a future where texting platforms don't allow cold calls from unknown contacts without an extra token. The extra token could come from a mutual friend who shared the contact, or an in-person contact exchange.

Josh Haberman avatar
Josh Haberman@JoshHaberman·16 Dec 2023

You can break a crate into private modules. But modules are allowed to have circular dependencies between them. So within a crate, there is no enforced discipline to prevent the crate from being arbitrarily tangled spaghetti.

Josh Haberman avatar
Josh Haberman@JoshHaberman·16 Dec 2023

Rust doesn't seem to have the concept of an internal/private crate. Any dependency of a public crate must also be publicly published on crates.io. There's no way to split a library into multiple crates in a way that is invisible to end users.

Josh Haberman avatar
Josh Haberman@JoshHaberman·15 Oct 2023

When I inspect the Rust extension, a lot of the file size seems to come from Gimli (DWARF parser), backtrace code, and addr2line. In other words, debugging functionality. Maybe this means that pyo3 will have amazing output when something goes wrong. Here's to hoping.

Josh Haberman avatar
Josh Haberman@JoshHaberman·15 Oct 2023

File size of a trivial Python extension (Rust/pyo3): 401kB File size of the protobuf Python extension (C): 277kB The Rust extension has a single function that adds two numbers. The C extension implements all of protobuf. Both figures exclude debug info.

Josh Haberman avatar
Josh Haberman@JoshHaberman·14 May 2022

Unfortunately this makes it more difficult to avoid copies and allocations. I'm rewriting some code to use Vec+indexes instead of arenas+references. It's working ok, but Vec is less efficient than an arena in multiple ways.

Josh Haberman avatar
Josh Haberman@JoshHaberman·14 May 2022

My biggest takeaway from Rust so far is that borrows should be relatively short-lived. While it is possible to put references in a long-lived struct, it creates spiraling complexity and is overall not worth it. Rust wants structs to own their members.

Josh Haberman avatar
Josh Haberman@JoshHaberman·4 Feb 2022

More ideas: - *printf() variants that are *not* affected by locale - setjmp()/longjmp() variants that do *not* touch the signal mask - qsort_r() - dtoa() (print shortest string that will round-trip a double)

Josh Haberman avatar
Josh Haberman@JoshHaberman·21 Nov 2021

You can create a Rust type that provides mutable operations that can be performed on a non-mutable reference. If you also made such a type Sync, that would be the best equivalent of a C++ thread-safe type.