HNHacker News
TopNewBestAskShowJobs

jmillikin

11,783 karma · joined March 23, 2009

https://john-millikin.com/

john@john-millikin.com

Currently semi-retired; formerly at Google (2011-2017) and Stripe (2017-2022)

submissionscomments
jmillikin··on Performance of the Python 3.14 tail-call interpreter
'eru implied `a += 1` has undefined behavior; I provided a trivial counter-example. If you'd like longer examples of C code that performs unsigned integer addition then the internet has many on offer.

I'm not claiming that C (or C++) is without problems. I wrote code in them for ~20 years and that was more than enough; there's a reason I use Rust for all my new low-level projects. In this case, writing C without undefined behavior requires lots of third-party static analysis tooling that is unnecessary for Rust (due to being built in to the compiler).

But if you're going to be writing C as "portable assembly", then the competition isn't Rust (or Zig, or Fortran), it's actual assembly. And it's silly to object to C having undefined behavior for signed integer addition, when the alternative is to write your VM loop (or whatever) five or six times in platform-specific assembly.

jmillikin··on Performance of the Python 3.14 tail-call interpreter
From a high-level academic view, yes, the compiler is allowed to perform any legal transformation. But in practice C compilers are pretty conservative about what they emit, especially when code is compiled without -march= .

You don't have to take my word for it. Go find a moderately complex open-source library written in C, compile it, then open up the result in Hexrays/Ghidra/radare2/whatever. Compare the compiled functions with their original source and you'll see there's not that much magic going on.

jmillikin··on Performance of the Python 3.14 tail-call interpreter
I'll expand my point to be clearer.

In C there is no operator overloading, so an expression like `a += 1` is easy to understand as incrementing a numeric value by 1, where that value's type is one of a small set of built-in types.

You'd need to look further up in the function (and maybe chase down some typedefs) to see what that type is, but the set of possible types generally boils down to "signed int, unsigned int, float, pointer". Each of those types has well-defined rules for what `+= 1` means.

That means if you see `int a = some_fn(); assert(a < 100); a += 1` in the C code, you can expect something like `ADD EAX,1` somewhere in the compiler output for that function. Or going the other direction, when you're in a GDB prompt and you disassemble the current EIP and you see `ADD EAX,1` then you can pretty much just look at the C code and figure out where you are.

---

Neither of those is true in C++. The combination of completely ad-hoc operator overloading, function overloading, and implicit type conversion via constructors means that it can be really difficult to map between the original source and the machine code.

You'll have a core dump where EIP is somewhere in the middle of a function like this:

  std::string some_fn() {
    some_ns::unsigned<int> a = 1;
    helper_fn(a, "hello");
    a += 1;
    return true;
  }
and the disassembly is just dozens of function calls for no reason you can discern, and you're staring at the return type of `std::string` and the returned value of `true`, and in that moment you'll long for the happy days when undefined behavior on signed integer overflow was the worst you had to worry about.
jmillikin··on Performance of the Python 3.14 tail-call interpreter
Show me a C compiler that miscompiles the following code and I'll concede the point:

  uint32_t add_1(uint32_t a) {
    a += 1;
    return a;
  }
jmillikin··on Performance of the Python 3.14 tail-call interpreter

  > This is a very good example of how C is not "close to the machine" or
  > "portable assembly",
C is very much "portable assembly" from the perspective of other systems programming languages of the 80s-90s era. The C expression `a += 1` can be trusted to increment a numeric value, but the same expression in C++ might allocate memory or unwind the call stack or do who knows what. Similarly, `a = "a"` is a simple pointer assignment in C, but in C++ it might allocate memory or [... etc].

The phrase "C is portable assembly" isn't a claim that each statement gets compiled directly to equivalent machine code.

jmillikin··on Rust inadequate for text compression codecs?
Biggest category of libraries that need inline assembly with compiler portability are compression/decompression codecs (like the linked article) -- think of images (PNG, JPEG), audio (MP3, Opus, FLAC), video (MPEG4, H.264, AV1).

Also important is cryptography, where inline assembly provides more deterministic performance than compiler-generated instructions.

Compiler intrinsics can get you pretty far, but sometimes dropping down to assembly is the only solution. In those times, inline assembly can be more ergonomic than separate .s source files.

jmillikin··on Rust inadequate for text compression codecs?
This sentence from the Reference is important:

  > The exact assembly code syntax is target-specific and opaque to the compiler
  > except for the way operands are substituted into the template string to form
  > the code passed to the assembler.
You can verify that rustc doesn't validate the contents of asm!() by telling it to emit the raw LLVM IR:

  % cat bogus.rs
  #![no_std]
  pub unsafe fn bogus_fn() {
   core::arch::asm!(".bogus");
   core::arch::asm!("bogus");
  }
  % rustc --crate-type=lib -C panic=abort --emit=llvm-ir -o bogus.ll bogus.rs
  % cat bogus.ll
  [...]
  ; bogus::bogus_fn
  ; Function Attrs: nounwind
  define void @_ZN5bogus8bogus_fn17h0e38c0ae539c227fE() unnamed_addr #0 {
  start:
    call void asm sideeffect alignstack ".bogus", "~{cc},~{memory}"(), !srcloc !2
    call void asm sideeffect alignstack "bogus", "~{cc},~{memory}"(), !srcloc !3
    ret void
  }
That IR is going to get passed to llvm-as and possibly onward to an external assembler, which is where the actual validation of instruction mnemonics and assembler directives happens.

---

The difference between llvm_asm!() and asm!() is in the syntax of the stuff outside of the instructions/directives -- LLVM's "~{cc},~{memory}" is what llvm_asm!() accepts more-or-less directly, and asm!() generates from backend-independent syntax.

I have an example on my blog of calling Linux syscalls via inline assembly in C, LLVM IR, and Rust. Reading it might help clarify the boundary: https://john-millikin.com/unix-syscalls#inline-assembly

jmillikin··on Rust inadequate for text compression codecs?

  > I’m all for multiple backends but there should be only 1 frontend. That’s
  > why I hope gccrs remains forever a research project - it’s useful to help
  > the Rust language people find holes in the spec but if it ever escapes the
  > lab expect Rust to pick up C++ disease.
An important difference between Rust and C++ is that Rust maintains a distinction between stable and unstable features, with unstable features requiring a special toolchain and compiler pragma to use. The gccrs developers have said on record that they want to avoid creating a GNU dialect of Rust, so presumably their plan is to either have no gccrs-specific features at all, or to put such features behind an unstable #![feature] pragma.

  > Rust with a gcc backend is fine for when you want gcc platform support
  > - a duplicate frontend with its own quirks serves no purpose.
A GCC-based Rust frontend would reduce the friction needed to adopt Rust in existing large projects. The Linux kernel is a great example, many of the Linux kernel devs don't want a hard dependency on LLVM, so they're not willing to accept Rust into their part of the tree until GCC can compile it.
jmillikin··on Rust inadequate for text compression codecs?
Note that becoming an international standard (via ISO, ECMA, IETF, or whatever) isn't necessary or sufficient to avoid dialects.

If the Rust language specification is precise enough to avoid disagreements about intended behavior, then multiple compilers can be written against that spec and they can all be expected to correctly compile Rust source code to equivalent output. Even if no international standards body has signed off on it.

On the other hand, if the spec is incomplete or underspecified, then even an ANSI/ISO/IETF stamp of approval won't help bring different implementations into alignment. C/C++ has been an ISO standard for >30 years and it's still difficult to write non-trivial codebases that can compile without modification on MSVC, GCC, Clang, and ICC because the specified (= portable) part of the language is too small to use exclusively.

Or hell, look at JSON, it's tiny and been standardized by the IETF but good luck getting consistent parsing of numeric values.

jmillikin··on Rust inadequate for text compression codecs?
The quoted statement is weaker than what you're reading it as, I think. It's not a statement that emitted assembly code is guaranteed to conform to LLVM syntax, it's just noting that (1) at present, (2) for supported targets of the rustc implementation, the emitted assembly uses LLVM syntax.

Non-LLVM compilers like gccrs could support platforms that LLVM doesn't, which means the assembly syntax they emit would definitionally be non-LLVM. And even for platforms supported by both backends, gccrs might choose to emit GNU syntax.

Note also that using a non-builtin assembler is sometimes necessary for niche platforms, like if you've got a target CPU that is "MIPS plus custom SIMD instructions" or whatever.

jmillikin··on Rust inadequate for text compression codecs?
You're talking about the syntax of the assembly code itself. In practice small variations between assemblers isn't much of a problem for inline assembly in the same way it would be for standalone .s sources, because inline assembly rarely has implementation-specific directives and macros and such. It's not like the MASM vs NASM split.

This thread is about the compiler-specific syntax used to indicate the boundary between C and assembly and the ABI of the assembly block (register ins/outs/clobbers). Take a look at the documentation for MSVC vs GCC:

https://learn.microsoft.com/en-us/cpp/assembler/inline/asm?v...

https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

Rust specifies the inline assembly syntax at https://doc.rust-lang.org/reference/inline-assembly.html in great detail. It's not a rustc extension, it's part of the Rust language spec.

jmillikin··on Rust inadequate for text compression codecs?
Rust's inline assembly syntax is part of the language, and in principle the same Rust source would compile on any conforming compiler (rustc, gccrs).

C/C++ doesn't have a standard syntax for inline assembly. Clang and GCC have extensions for it, with compiler-specific behavior and syntax.

jmillikin··on Chicory: A JVM native WebAssembly runtime
The JVM was designed with the intention of being a secure sandbox, and a lot of its early adoption was as Java applets that ran untrusted code in a browser context. It was a serious attempt by smart people to achieve a goal very similar to that of WebAssembly.

Unfortunately Java was designed in the 1990s, when there was much less knowledge about software security -- especially sandboxing of untrusted code. So even though the goal was the same, Java's design had some flaws that made it difficult to write a secure JVM.

The biggest flaw (IMO) was that the sandbox layer was internal to the VM: in modern thought the VM is the security boundary, but the JVM allows trusted and untrusted code to execute in the same VM, with java.lang.SecurityManager[0] and friends as the security mechanism. So the attack surface isn't the bytecode interpreter or JIT, it's the entire Java standard library plus every third-party module that's linked in or loaded.

During the 2000s and 2010s there were a lot of Java sandbox escape CVEs. A representative example is <https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-0422>. Basically the Java security model was broken, but fixing it would break backwards compatibility in a major way.

--

Around the same time (early-mid 2010s) there more thought being put into sandboxing native code, and the general consensus was:

- Sandboxing code within the same process space requires an extremely restricted API. The original seccomp only allowed read(), write(), exit(), and sigreturn() -- it could be used for distributed computation, but compiling existing libraries into a seccomp-compatible dylib was basically impossible.

- The newly-developed virtualization instructions in modern hardware made it practical to run a virtual x86 machine for each untrusted process. The security properties of VMs are great, but the x86 instruction set has some properties that make it difficult to verify and JIT-compile, so actually sitting down and writing a secure VM was still a major work of engineering (see: QEMU, VMWare, VirtualBox, and Firecracker).

Smartphones were the first widespread adoption of non-x86 architectures among consumers since PowerPC, and every smartphone had a modern web browser built in. There was increasing desire to have something better than JavaScript for writing complex web applications executing in a power-constrained device. Java would have been the obvious choice (this was pre-Oracle), except for the sandbox escape problem.

WebAssembly combines architecture-independent bytecode (like JVM) with the security model of VMs (flat memory space, all code in VM untrusted). So you can take a whole blob of legacy C code, compile it to WebAssembly, and run it in a VM that runs with reasonable performance on any architecture (x86, ARM, RISC-V, MIPS, ...).

jmillikin··on Chicory: A JVM native WebAssembly runtime

  > The extent of how each bytecode was used doesn't invalidate their existence.
It does, because uptake is the proof of suitability to purpose. There's no credit to just being first to think of an idea, only in being first to implement it well enough that everyone wants to use it.

  > Any bytecode can be embedded, it is a matter of implementation.
Empty sophistry is a poor substitute for thought. Are you going to post any evidence of your earlier claim, or just let it waft around like a fart in an elevator?

In particular, your reference to ANDF is absurd and makes me think you're having this discussion in bad faith. I remember ANDF, and TenDRA -- I lost a lot of hours fighting the TenDRA C compiler. Nobody with any familiarity with ANDF would put it in the same category as WebAssembly, or for that matter any other reasonable bytecode.

For anyone who's reading this thread, check out the patent (https://patents.google.com/patent/EP0464526A2/en) and you'll understand quickly that ANDF is closer to a blend of LLVM IR and Haskell's Cmm. It's designed to be used as part of a multi-stage compiler, where part of the compiler frontend runs on the developer system (emitting ANDF) and the rest of the frontend + the whole backend + the linker runs on the target system. No relationship to WebAssembly, JVM bytecode, or any other form of bytecode designed to be executed as-is with predictable platform-independent semantics.

  > More than 20 programming tools vendors offer some 26 programming languages
  > — including C++, Perl, Python, Java, COBOL, RPG and Haskell — on .NET.
I want to see you explain why you think the CLR pre-dates the JVM. Or explain why you think C++/CLI is the same as compiling actual standard C/C++ to WebAssembly.

  > Naturally one can always advocate that since 60 years of history have not 
  > provided that very special feature XYZ, we should now celebrate WebAssembly
  > as the be all end all of bytecode, as startups with VC money repurpose old
  > ideas newly wrapped.
Yes, it is in fact normal to celebrate when advances in compiler implementation, security research and hardware performance enable a new technology that solves many problems without any of the downsides that affected previous attempts in the same topic.

If you reflexively dislike any technology that is adopted by startups, and then start confabulating nonsense to justify your position despite all evidence, then the technology isn't the problem.

jmillikin··on Chicory: A JVM native WebAssembly runtime
I've had the misfortune of working professionally with CORBA, and I've spent some time trying to keep up with WIT/WASI/that whole situation. Whatever WIT is going to be, I can assure you it's very different from CORBA.

The best way I think to describe WIT is that it seems to be an attempt to design a new ABI, similar to the System V ABI but capable of representing the full set of typesystems found in every modern language. Then they want to use that ABI to define a bunch of POSIX-ish syscalls, and then have WebAssembly as the instruction set for their architecture-independent executable format.

The good news is that WIT/WASI/etc is an independent project from WebAssembly, so whether it succeeds or fails doesn't have much impact on the use of WebAssembly as a plugin mechanism.

jmillikin··on Chicory: A JVM native WebAssembly runtime
Ok, show me a bytecode from the 60s (or 90s!) to which I can compile Rust or Go and then execute with near-native performance with a VM embedded in a standard native binary.

The old bytecodes of the 20th century were designed to be a compilation target for a single language (or family of closely-related languages). The bytecode for Erlang is different from that of Smalltalk is different from that of Pascal, and that's before you start getting into the more esoteric cases like embedded Forth.

The closest historical equivalent to today's JVM/CLR/WebAssembly I can think of is IBM's hardware-independent instruction set, which I don't think could be embedded and definitely wasn't portable to microcomputer architectures.

jmillikin··on Chicory: A JVM native WebAssembly runtime
Yeah, pretty much all of them are written in either Go or Rust. The Go tools pull in the Go standard library's Go parser to do things like compute dependencies via package imports, and the Rust ones use the Cargo libraries to parse Cargo.toml files.

From the perspective of a Bazel ruleset maintainer, precompiled helper tools are much easier to provide if your language has easy cross-compilation. So maybe one day Zig will start to make an appearance too.

jmillikin··on Chicory: A JVM native WebAssembly runtime
The WebAssembly bytecode semantics are important to security because they make it possible to (1) be a compilation target for low-level languages, and (2) implement small secure interpreters (or JITs) that run fast enough to be useful. That's why WebAssembly is being so widely implemented.

Java was on a path to do what WebAssembly is doing now, back in the '90s. Every machine had a JRE installed, every browser could run Java applets. But Java is so slow (and its sandboxing design so poor) that the world gave up on Java being able to deliver "compile once run anywhere".

If you want to take a second crack at Sun's vision, then you can go write your own embedded JVM and try to convince people to write an LLVM backend for it. The rest of us gave up on that idea when applets were removed from browsers for being a security risk.

jmillikin··on Chicory: A JVM native WebAssembly runtime
None of what 'jcmfernandes lists are part of WebAssembly. At best they can be considered related technologies, like the relationship between the JVM and JavaBeans.

And in terms of design, they're closer to COM or OLE. The modern replacement for CORBA/DCOM/etc is HTTP+JSON (or gRPC), which doesn't try to abstract away the network.

jmillikin··on Chicory: A JVM native WebAssembly runtime
WebAssembly doesn't have access to the high-resolution timers needed for Spectre attacks unless the host process intentionally grants that capability to the sandboxed code.

See this quote from the paper you linked:

""" Our attacks extend Google’s Safeside [24] suite and, like the Safeside POCs, rely on three low-level instructions: The rdtsc instruction to measure execution time, the clflush instruction to evict a particular cache line, and the mfence instruction to wait for pending memory operations to complete. While these instructions are not exposed to Wasm code by default, we expose these instructions to simplify our POCs. """

The security requirements of shared-core hosting that want to provide a full POSIX-style API are unrelated to the standard use of WebAssembly as an architecture-independent intermediate bytecode for application-specific plugins.

'gf000 correctly notes that WebAssembly's security properties are basically identical to any other interpreter, and there's many options for bytecodes (or scripting languages) that can do some sort of computation without any risk of a sandbox escape. WebAssembly is distinguished by being a good generic compilation target and being easy to write efficient interpreters/JITs for.

jmillikin··on Chicory: A JVM native WebAssembly runtime
Chicory seems like it'll be pretty useful. Java doesn't have easy access to the platform-specific security mechanisms (seccomp, etc) that are used by native tools to sandbox their plugins, so it's nice to have WebAssembly's well-designed security model in a pure-JVM library.

I've used it to experiment with using WebAssembly to extend the Bazel build system (which is written in Java). Currently there are several Bazel rulesets that need platform-specific helper binaries for things like parsing lock files or Cargo configs, and that's exactly the kind of logic that could happily move into a WebAssembly blob.

https://github.com/jmillikin/upstream__bazel/commits/repo-ru...

https://github.com/bazelbuild/bazel/discussions/23487

jmillikin··on Police arrest apparent leader of 'Zizian' group
> the rationalist community grew around publications by Eliezer Yudkowsky

Rationalism (in its current form) has been around since long before someone on the internet became famous for their epic-length Harry Potter fanfiction, and it will continue to exist long after LessWrong has become a domain parking page.

jmillikin··on PG&E reports profit of more than $2B for 2024
The trouble with PG&E is that it's trying to serve two incompatible goals.

The shareholders want it to provide electric service for a profit in the locales where doing so is economically sensible (= urban/suburban), slowly grow its value, and throw off a stable stream of dividends. This is the basic value proposition of all for-profit utilities: low growth, low volatility, stable income.

The state government -- and a not insubstantial proportion of the state population -- want PG&E to be a non-profit that provides electricity at cost to everyone in its coverage area, which is to include huge swaths of forest-covered hillsides and dry rural scrubland. Every time it gets mentioned on HN (not exactly a hotbed of communism!) there's a bunch of comments about how it should be illegal for an electric utility to have any profit at all.

PG&E can't have it both ways. It hasn't paid a non-trivial dividend since 2017 and its share price is ~half of what it was 20 years ago, which makes it an astonishingly poor investment -- compare to Southern Company (SO) or Duke Energy (DUK). But at the same time it is legally mandated to absorb the costs of operating high-voltage lines in brushfire territory, and half its customers think it shouldn't be allowed to exist.

jmillikin··on PG&E reports profit of more than $2B for 2024
In Japan utilities are separated into pseudo-governmental entities that operate the infrastructure as a monopoly, and for-profit companies that deal directly with customers. This seems to work relatively well in that the customer-facing companies can distinguish themselves in the market (e.g. offering higher prices but better customer service), and the infrastructure is immune to profit incentives but subjected to high levels of regulation.

The closest equivalent I experienced in the states is when I lived in the SF bay area and got internet access as a customer of Sonic, who provided DSL services over copper lines owned by AT&T.

jmillikin··on In the trenches: on being an Engineering Manager
Many professions have legally protected titles. In the USA it's illegal for someone without a CPA license to claim the title of "certified public accountant", and since engineering failures can have fatal consequences the same protection is offered to the title "engineer" (or "professional engineer", etc) in some countries.

You might argue that it's the certification that matters, not the title, but the title of "structural engineer" has been around for approximately as long as humans have been stacking up rocks to sleep under; the certifications have not.

jmillikin··on In the trenches: on being an Engineering Manager
I meant avionics/skyscrapers -- edited to disambiguate.

The idea that most software developers are working in low-skill positions (i.e. distributing the output of an LLM over their Jira queue) is probably not as wrong as I wish it was, but those kind of developers aren't interested in software development as a craft to begin with, so I think (hope?) they aren't anywhere close to comprising most of the HN readership.

Also those positions don't pay as well; HN cares more about the $600k/yr jobs than the $60k/yr ones, and nobody pays $600k/yr for someone to copy-paste NPM invocations from Stack Overflow.

jmillikin··on In the trenches: on being an Engineering Manager
There's a difference between software developers who glue together libraries to build cat picture voting sites and software developers who write real-time avionics firmware. The second type of developer can reasonably claim to be "software engineers" -- blueprints for a garden shed and for a skyscraper are distinguished by content, not medium.

Between those two limits the line must be drawn somewhere, and honest people will disagree about exactly where, but it seems reasonable to claim that people working in most software development positions of interest to Hacker News are closer to the latter than the former.

If you want to claim that junior developers are apprentices (journeymen? are apprentices interns?) and senior/staff/principal/whatever are engineers then that's fine (if idiosyncratic), but that's not what other people mean when they say or hear "software developers aren't engineers".

jmillikin··on The Evolution of SRE at Google
SREs are programmers who specialize in writing programs that manage complex distributed systems.

If you hire SREs and have them doing sysadmin work, then (1) you're massively over-paying and (2) they'll get bored and leave once they find a role that makes better use of their skills.

If you hire sysadmins for SRE work, they'll get lost the first time they need to write a kernel module or design a multi-continent data replication strategy.

jmillikin··on Chip Cities Rise in Japan's Fields of Dreams
Sapporo is denser than an American city would be with the same population, for cultural and geographic reasons. And in Japan it's common to have a train commute of 30-60 minutes, though living in Sapporo and commuting to a suburb might be considered more of a "reverse commute" (other direction is more common here IME).

Not to mention that Chitose is where Sapporo's international airport is located, so someone who travels often might find it more convenient than living in Sapporo proper.

jmillikin··on Safe and efficient C++ interoperability via non-escapable types and lifetimes
https://danielchasehooper.com/posts/why-swift-is-slow/
← PreviousPage 2 of 34Next →