Skip to content

Comment on Zig’s Io.Threaded is neatparent

Comments

I know some people hate on it, but I genuinely think that NIO is pretty good just in general.

It actually kind of annoys me; I feel like most Java code I've had to debug/maintain is slow and terrible because most Java engineers lack any ambition so they write the old terrible IO that they learned in university, and for years I guess I kind of erroneously assumed that Java was "bad" at doing IO.

Then I read a book on NIO, started writing my own code with channels and selectors and realized that it actually works quite well, and I found it relatively intuitive and performance was pretty solid.

This is actually a recurring pattern I've found in the Java world; Java has added a lot of great features over the years that make the language more ergonomic and performant and fun to write, but due to its prevalence in the "Enterprise" world and university, it selection biases towards people who refuse to learn anything new, meaning that a lot (the majority?) of Java code feels like it was written in 1997.

I have been writing a lot of Java in my free time, unapologetically using Java 17, 21, and 25 features, and I am actually enjoying it.

Run with the options to dump optimized code to a file. Look at what it’s actually generating for all the byte buffer calls and you’ll see it’s piss-takingly fast. Looking at the Java it shows up as five virtual calls and a bunch of bounds checks. The JIT will turn that into a single x86 instruction in most cases.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.