HNHacker News
TopNewBestAskShowJobs

nelhage

1,489 karma · joined February 17, 2008

submissionscomments
nelhage··on Performance of the Python 3.14 tail-call interpreter
(author here)

> The problem is 95% about laying out the instruction dispatching code for the branch predictor to work optimally.

A fun fact I learned while writing this post is that that's no longer true! Modern branch predictors can pretty much accurately predict through a single indirect jump, if the run is long enough and the interpreted code itself has stable behavior!

Here's a paper that studied this (for both real hardware and a certain simulated branch predictor): https://inria.hal.science/hal-01100647/document

My experiments on this project anecdotally agree; they didn't make it into the post but I also explored a few of the interpreters through hardware CPU counters and `perf stat`, and branch misprediction never showed up as a dominant factor.

nelhage··on Performance of the Python 3.14 tail-call interpreter
> Btw, what about some clang18.tc comparison

(post author here) Oh, this is something I could have called out explicitly: The tail-calling interpreter relies on a feature (the `preserve_none` calling convention) that only landed in clang-19. That means you can only test it on that version. That coincidence (that 19 added both this feature, and the regression) is part of why this was so easy to miss at first, and why I had to "triangulate" with so many different benchmarks to be confident I understood what was going on.

nelhage··on Transformers for software engineers
(author here)

I actually did a v0 writeup in Go, but I wanted a language that had a bit more powerful type system and more support for a fluent/functional style in some of the expressions. I was optimizing for what I know and felt was highly expressive; I've since gotten a bunch of feedback from people who are interested in the content but not comfortable reading Rust, so perhaps it wasn't the best choice.

nelhage··on Rust: Dropping heavy things in another thread can make your code 10000x faster
We used precisely this optimization in [sorbet](https://sorbet.org), a brand-new type checker for Ruby, which also contains a high-performance LSP server.

We wrote the entire thing (and tested, using ASAN and fuzzers and other techniques) to avoid leaking memory, and then strategically inserted [the equivalent of a rust `mem::forget`](https://github.com/sorbet/sorbet/blob/0aae56e73c7680ec6053b3...) into the end of the `main` driver during standalone mode, to avoid calling those destructors when we're about to exit anyways.

This optimization is definitely still relevant for new systems today.

nelhage··on Botnet Controls “Twitch Installs Arch Linux”
Better yet, just run this on a t2.micro on a throwaway EC2 account. Doesn't matter if they own the box, they get literally nothing they couldn't get for free from Amazon anyways.
nelhage··on Indices Point Between Elements
zero-width matches (and empty lines) were a huge source of stupid edge-case bugs in livegrep[1], and being rigorous about maintaining this mental model definitely helped a lot.

[1] livegrep.com

nelhage··on Indices Point Between Elements
I get into this a bit later on, but I think the exact same model applies to pointers: You're much better off in most cases thinking of pointers as pointing at the zero-width points between elements, than at elements themselves.
nelhage··on Running three hours of Ruby tests in under three minutes
Live data, but they're stored redacted, and/or with sensitive data (e.g. credit card numbers) replaced with opaque tokens that reference an encrypted store that's carefully access-controlled.
nelhage··on Running three hours of Ruby tests in under three minutes
This is a great question, and it's definitely a problem we have.

We don't have a single answer we use for every system we work on, but we employ a few common patterns, ranging from just keeping hard-coded strings containing the expected output, up to and including implementing our own fake versions of external infrastructure. We have, for example, our own faked ISO-8583 [1] authorization service, which some of our tests run against to get a degree of end-to-end testing.

Back-testing is also incredibly valuable: We have repositories of every conversation or transaction we've ever exchanged with the banking networks, and when making changes to parsers or interpreters, we can compare their output against the old version on all of that historical data.

[1] https://en.wikipedia.org/wiki/ISO_8583

nelhage··on Running three hours of Ruby tests in under three minutes
Our testing running infrastructure spins up a pool of database instances on each worker machine, one for each worker process. The test spinup and teardown code handles schema management, hooking into our DB access layer to create and clean up database tables only if they're used by a given test.
nelhage··on Game of Thrones leak and watermark: a stupid tracking system
Why do we think the blur is sufficient? The blur loses information, but there are presumably a small number of watermarked versions, and a lot of frames. It's almost certainly possible for HBO to reverse-engineer the blur algorithm — I bet it's a stock option from a common tool — and then run it over all the originals and see which produces the best post-blur match.
nelhage··on Stripe CTF3: Distributed Systems is live
You're getting that even with a statically-compiled binary? What's the output of "file ./level0"?
nelhage··on Tracking down a memory leak in Ruby's EventMachine
(author here) Yeah, there are a lot of such tools, and they can be invaluable. In my experience, though, if you're working with a large, complex system, including pieces like Ruby and OpenSSL which do some grody tricks internally, they'll flag lots of false positives and noise, and it takes a lot of work to get a development environment where they work well.

Also, we weren't yet sure whether this bug was reproducible in development/QA, or was only triggerable in production, so using techniques that worked directly on the running image was attractive.

nelhage··on Announcing MoSQL
We've been pretty happy so far. There have been a few rough edges getting it up and keeping it running, but we've been very impressed with the performance so far.

I've passed your comment on to Colin, who wrote the Ruby client -- I'm sure he'll appreciate it!

nelhage··on Announcing MoSQL
There isn't support. It's definitely something I've pondered. If you're interested in adding support, I'd be happy to hear from you at (my username) AT stripe.com.
nelhage··on Announcing MoSQL
MoSQL will just throw any fields it doesn't recognize into a JSON "extra_props" field (if you ask it to). So everything will work fine, and existing SQL code (which doesn't know about those fields) will continue to be fine.

If you need the data in SQL, you can either parse the JSON somehow, or rebuild the SQL table with a MoSQL schema that knows about the new fields.

nelhage··on Announcing MoSQL
They each have different advantages and strengths.

MongoDB is great for failover and for rapid development or prototyping. SQL is great for reporting or analytics, since you can do all kinds of aggregates and JOINs right in the database.

The edge cases where you can't represent the data perfectly aren't a huge deal for this use case -- because it's a one-way export, you don't have to be able to round-trip the data, and as long as you can export the data you want to run analysis on, it doesn't matter if there's some you can't get.

nelhage··on Announcing MoSQL
(I wrote MoSQL)

I actually played with mongo_fdw. At this point, it's a really cute hack, and useful for some things, but it doesn't give Postgres enough information and knobs to really let the query planner work effectively, so it ends up being really slow for complex things. I do love the concept, though.

nelhage··on Announcing MoSQL
I actually prototyped our PostgreSQL solution using mongo_fdw (Incidentally, I throw together Debian packaging here, if you're interested: https://github.com/nelhage/mongo_fdw).

Our experience was that mongo_fdw doesn't (yet?) give postgres enough information and knobs to plan JOINs efficiently, which is one of the things we wanted. I got a decent amount of leverage out of using mongo_fdw and then cloning to native tables using SELECT INTO, though :)

nelhage··on Announcing MoSQL
To pick one, we like the fact that MongoDB lets you change your schema and add new fields to your documents without having to worry about migrations or keeping track of schema versions, or any of that.

You could build something like that on top of SQL, but it's nice to have a tool where you don't have.

nelhage··on Announcing MoSQL
(I wrote MoSQL)

PostgreSQL scales surprisingly well for this purpose, and is much nicer for interactive queries than Hadoop/Hive. We use Impala[1] for some larger datasets, but Impala is comparatively new, and it's nice to have something as battle-tested as postgres here.

As for the "why do we need realtime?": In my mind the benefit of a near-realtime replica is not that you actually often need it, but that it means you never have to ask the question of "Was this snapshot refreshed recently enough?", and never end up having to wait several hours for an enormous dump/load operation, when you realize you did need newer data.

[1] http://blog.cloudera.com/blog/2012/10/cloudera-impala-real-t...

nelhage··on MultiXml gem has same vulnerability as Rails' CVE-2013-0156 – patch now
I strongly recommend loading something like this in your Ruby applications: https://gist.github.com/4507129

It will prevent YAML.rb from instantiating arbitrary objects, which will close off this entire class of problems.

Obviously, if you do use YAML as a serialization format for arbitrary objects, this won't work, but odds are you aren't doing that.

nelhage··on Changes coming in Version 1.1 of the Twitter API
Really? 6 month from turning it on to disabling 1.0 is really not that long a time at all. In that time, every client needs to migrate to 1.1 and QA that, and then all the distribution channels (distros, app stores, etc.) all need to get updated versions, and then users all need to upgrade. 6 months is extremely optimistic for that to all happen.
nelhage··on Linux code search
See also my project, http://livegrep.com, which is very similar but does support regular expressions (and feels much snappier on the frontend to me, although his does claim comparable backend times).
nelhage··on Livegrep: Live searching the Linux kernel source code
I'm using a different data structure -- a suffix array -- but the concept is pretty similar. I started work on this before Russ released his codesearch implementation, but I did read his blog posts while I was working on this.
nelhage··on Livegrep: Live searching the Linux kernel source code
Lucene, and most other indexing solutions (to my knowledge) index based on words, not arbitrary substrings.

So they can efficiently answer questions like "Give me all documents containing the word 'Linus'", but not necessarily "All documents containing the string '#def'".

That said, I am indexing -- I have my own custom backend that stores an in-memory index that lets me do arbitrary substring search (and more complicated queries, such as most character classes) much faster than a full search.

That said, the backend will fall back on a full regex search if necessary.

nelhage··on Livegrep: Live searching the Linux kernel source code
Hey there. I built this. Top 10 queries, all lengths:

f,s,fu,fuck,fuc,a,c,p,d,t

Top 10, >=4 characters:

fuck,shit,peni,penis,linu,craz,cunt,linus,test,hell

I weep for humanity :)

nelhage··on Mosh: SSH for 2012
Well, it helps in that you need to initiate a connection much less often. Once you have a connected mosh session, it will transparently roam with you, across suspend/resume or changing networks, as long as you like.

But yes, it can't help with the initial connection, which has to be bootstrapped over ssh.

nelhage··on Mosh: SSH for 2012
The killer app is not actually the predictive echo, but the improved handling of lossy networks and roaming between networks. On a crappy wifi hotspot that regularly craps out for a few seconds? mosh will notice and recover the instant it comes back, whereas ssh will have a delay or may not recover at all. Suspend your laptop with an active connection and come up an hour later on a different connection? mosh will instantly restablish connection like nothing happened.
nelhage··on SICP is being taught again at MIT
This website is current. I'm one of the alumni involved in this version of the course.

To give some more context, this is a course taught by a group of MIT alumni over MIT's "IAP" January term (http://web.mit.edu/iap/). As such, it's only 8 lectures over the course of a month, not a full semester-long class. It's partially sponsored by the EECS department and worth 6 units of P/D/F credit, but is not affiliated with the official EECS curriculum in any way, and does not fulfill any department requirements.

It's mostly just an effort by a few of us who loved SICP to give students these days an opportunity to be exposed to some of the Big Ideas from the class, that we feel haven't really found their way into the revamped curriculum.

Page 1 of 2Next →