HNHacker News
TopNewBestAskShowJobs

OskarS

8,392 karma · joined September 4, 2016

submissionscomments
OskarS··on Is Rust faster than C?
qsort is obviously just an example, this situation applies to anything that takes a callback: in C++/Rust, that's almost always generic and the compiler will monomorphize the function and optimize around it, and in C it's almost always a function pointer and a userData argument for state passed on the stack. (and, of course, it applies not just to callbacks, but more broadly to anything templated).

I'm actually very curious about how good C compilers are at specializing situations like this, I don't actually know. In the vast majority cases, the C compiler will not have access to the code (either because of dynamic linking like in this example, or because the definition is in another translation unit), but what if it does? Either with static linking and LTO, or because the function is marked "inline" in a header? Will C compilers specialize as aggressively as Rust and C++ are forced to do?

If anyone has any resources that have looked into this, I would be curious to hear about it.

OskarS··on Is Rust faster than C?
It's interesting, because it's a "cultural" thing like the author discusses, it's a very good point. Sure, you can do unsafe integer arithmetic in Rust. And you can do safe integer arithmetic with overflow in C/C++. But in both cases, do you? Probably you don't in either case.

"Culturally", C/C++ has opted for "unsafe-but-high-perf" everywhere, and Rust has "safe-but-slightly-lower-perf" everywhere, and you have to go out of your way to do it differently. Similarly with Zig and memory allocators: sure, you can do "dynamically dispatched stateful allocators that you pass to every function that allocates" in C, but do you? No, you probably don't, you probably just use malloc().

On the other hand: the author's point that the "culture of safety" and the borrow checker in Rust frees your hand to try some things in Rust which you might not in C/C++, and that leads to higher perf. I think that's very true in many cases.

Again, the answer is more or less "basically no, all these languages are as fast as each other", but the interesting nuance is in what is natural to do as an experienced programmer in them.

OskarS··on Is Rust faster than C?
I think personally the answer is "basically no", Rust, C and C++ are all the same kind of low-level languages with the same kind of compiler backends and optimizations, any performance thing you could do in one you can basically do in the other two.

However, in the spirit of the question: someone mentioned the stricter aliasing rules, that one does come to mind on Rust's side over C/C++. On the other hand, signed integer overflow being UB would count for C/C++ (in general: all the UB in C/C++ not present in Rust is there for performance reasons).

Another thing I thought of in Rust and C++s favor is generics. For instance, in C, qsort() takes a function pointer for the comparison function, in Rust and C++, the standard library sorting functions are templated on the comparison function. This means it's much easier for the compiler to specialize the sorting function, inline the comparisons and optimize around it. I don't know if C compilers specialize qsort() based on comparison function this way. They might, but it's certainly a lot more to ask of the compiler, and I would argue there are probably many cases like this where C++ and Rust can outperform C because of their much more powerful facilities for specialization.

OskarS··on Lessons from Hash Table Merging
> HashMap implements Extend, so just h0.extend(h1) and you're done, the people who made your HashMap type are much better equipped to optimize this common operation.

Are you sure? I'm not very used to reading Rust stdlib, but this seems to be the implementation of the default HashMap extend [1]. It just calls self.base.extend. self.base seems to be hashbrown::hash_map, and this is the source for it's extend [2]. In other words, does exactly the same thing, just iterates through hash map and inserts it.

Maybe I'm misreading something going through the online docs, or Rust does the "random seed" thing that abseil does, but just blinding assuming something doesn't happen "because Rust" is a bit silly.

[1]: https://doc.rust-lang.org/src/std/collections/hash/map.rs.ht...

[2]: https://docs.rs/hashbrown/latest/src/hashbrown/map.rs.html#4...

OskarS··on How to stop Linux threads cleanly
The tricky part is really point 2 there, that can be harder than it looks (e.g. even simple file I/O can be network drives). Async IO can really shine here, though it’s not exactly trivial designing async cancelletion either.
OskarS··on How to stop Linux threads cleanly
Feel free to read the article before commenting.
OskarS··on Deterministic multithreading is hard (2024)
Never heard of this, I’m really interested in digging into this paper. Thank you both for the tip!
OskarS··on Beliefs that are true for regular software but false when applied to AI
No, but if you phrase it like "there are multiple correct answers to the question 'I have a list of integers, write me a computer program that sorts it'", that is obviously true. There's an enormous variety of different computer programs that you can write that sorts a list.
OskarS··on HTTP3 Explained
Is the protocol inherently inferior in situations like that, or is this because we've spent decades optimizing for TCP and building into kernels and hardware? If we imagine a future where QUIC gets that kind of support, will it still be a downgrade?
OskarS··on Python 3.14 is here. How fast is it?
No, this is very much not the same. The Raku version is like writing this in Python:

    def fibonacci():
        a, b = 0, 1

        while True:
            yield a
            a, b = b, a+b
And taking the 40th element. It's not comparable at all to the benchmark, that's deliberately an extremely slow method of calculating fibonacci numbers for the purpose of the benchmark. For this version, it's so fast that the time is dominated by the time needed to start up and tear down the interpreter.
OskarS··on Thoughts on the Word Spec in Rust
That is true, cap’n proto and flatbuffers are excellent realizations of this basic concept. But that’s very different thing from what the commenter is talking about Word doing in the 90s, of just memory-mapping the internal data structures and be done with it.
OskarS··on Nobel Prize in Literature 2025: László Krasznahorkai
Your argument is that it’s not ok to think of all Jewish people as a monolithic group, and therefore his statement where he considered all arabs as a monolithic group is ”legitimate”? Seriously?

Just like it’s not ok to see all jews as part of the same murderous conspiracy, it’s not ok to see all arabs as part of one either.

OskarS··on Thoughts on the Word Spec in Rust
You can absolutely save data like that, it's just that it's a terrible idea. There are obvious portability concerns issues: little-endian vs. big endian, 32-bit vs. 64-bit, struct padding, etc.

Essentially, this system works great if you know the exact hardware and compiler toolchain, and you never expect to upgrade it with things that might break memory layout. Obviously this does not hold for Word: it was written originally in a 32-bit world and now we live in a 64-bit one, MSVC has been upgraded many times, etc. There's also address space concern: if you embed your pointers, are you SURE that you're always going to be able to load them in the same place in the address space?

The overhead of deserialization is very small with a properly written file format, it's nowhere near worth the sacrifice in portability. This is not why Word is slow.

OskarS··on Way past its prime: how did Amazon get so rubbish?
Yeah, I do this on occassion as well, but I aleays try the Swedish retailers first, and only go to Amazon when I can’t find whatever I’m looking for. It’s pretty rare I have to go to Amazon.

It’s rough, because you know that it will probably be cheaper and delivered faster from Amazon, at the moment it is probably the most consumer friendly place to buy. But you know once the honeymoom is over and all the Swedish retailers are gone, it’s just going to devolve to garbage. Support your non-Amazon retailers!

OskarS··on Way past its prime: how did Amazon get so rubbish?
And because they’re new, we have plenty of homegrown internet retailers for competition. Personally, I avoid Amazon in favor of the others if at all possible, seems like there’s a really significant risk Amazon is going to wipe them out.
OskarS··on The Beer Can (2023)
I was wondering about the water and sewage pipes the author mentioned going through these unheated areas. Are the pipes heated? Or just so well-insulated that the contents doesn't have time to freeze before reaching their destination?
OskarS··on Asked to do something illegal at work? Here's what these software engineers did
We're not talking about living in a totalitarian state and breaking the law by aiding the resistance here. The cases in the article is like committing financial fraud or faking customer data. And then, yeah, I do think there is no excuse for going along with it, you have a duty as a member of society not to do such things, even if it costs your your job. It's not easy, and as I said I have enormous sympathy for a person in this position, but there is a clear right thing to do, and you have an obligation to act accordingly.
OskarS··on Asked to do something illegal at work? Here's what these software engineers did
I would argue that you have a moral and ethical responsibility to say no when your manager asks you to do something illegal, even if it does cost you your job. The law is the law, and there is no excuse for breaking it. Your manager is certainly culpable, but if you act against the law, you are culpable as well.

The exception is if you fear literal physical violence against you or others, or are being blackmailed or something, then of course you are being coerced and have no choice. But "losing your job" does not rise to that kind of coercion, in my opinion.

Not saying it's easy, it's a horrible situation to be put in and I have huge amounts of sympathy for a person who has to experience this. No one is perfect and act with faultless ethics at all times. But hard or not, it is your duty as a citizen not to violate the law.

OskarS··on The ABS programming language
You can do that by using mkfifo relatively easy, but I take your point. In that sense, the most "flexible" language is pure C, because you can do anything there. I guess a better word is "ergonomic": if you want to do `curl something | grep whatever > output.txt` in C or Python or whatever other general purpose language, it's MUCH more difficult. Writing lines like that is trivial for me in shell scripting, I just did it in this comment. If I had to do it in Python, I would have to spend 20 minutes studying the precise flags to pass to subprocess.Popen and think really hard about which streams to call .close() on and when. God help me if I was doing it in C and using fork()/exec().

This is the shell scripting super-power, all this stuff is just trivial.

OskarS··on The ABS programming language
Yeah, and environment variables as well. It's notable that the syntax for reading an environment variable in bash is identical to the syntax for reading a "normal", process local variable (though setting is slightly different, you have to use "export"). It's like the ground scope is "the computing environment" (files, processes, env vars, ...), not the "program sandbox".
OskarS··on The ABS programming language
The superpower of shell scripting languages is not just that it's easy to run external processes, it's also that you can run them extremely flexibly: chain them into pipelines, run them in background, redirecting streams, process substitution, etc. These kinds of things is why "just use Python or whatever!" is not always a great answer to "shell scripting sucks" (which it does, I agree). I mean, you CAN do all those things in Python, but it's a huge pain in the ass to write compared to the dedicated syntax of shell scripting.

If the developers of ABS are reading this, it would be great some examples of that kind of thing to the homepage. Like, how would you do `curl <url> | grep something | sort | uniq | tee output.txt`? What about process substitution? What about redirecting stderr to stdout? And, the biggest problem with shell scripting is escaping problems, how does ABS handle that? Can you run a command with an array of strings as argument instead of having the shell split on (unescaped and unquoted) spaces?

OskarS··on `std::flip`
You write C++ every day, and you didn’t understand the is_descendant_of/is_ancestor_of example? Or how you can use it to reverse a relation like std::less?
OskarS··on Huntington's disease treated for first time
This is incredible, what a miraculous thing for sufferers and their families. Feels rare to see such a such an unquestionably good news story these days.
OskarS··on 40k-Year-Old Symbols in Caves Worldwide May Be the Earliest Written Language
I should explain a little further what I mean: there are "pure" ideograms even in English, like the & and % characters. These unambiguously refer to the words "and" and "percent", but the way they're written gives no clue whatsoever to a reader on how they're pronounced. If you had gone your entire life reading and writing English but somehow never encountered them, the way they're written is entirely unhelpful. Emoji are an even more abstract example, that don't even correspond to any word at all, just usually indicating mood or something like that.

It's a common misconception that all Chinese characters are like that, but my understanding is that while there are many, many more ideograms in Chinese than English, something like 80% of the characters do in some way indicate pronunciation (even if it's just something like tone) or use the "rebus principle" or something like that. So again, it's a spectrum, but all writing systems are phonetic to some extent. Human's wouldn't be able to use it to communicate effectively otherwise.

I will say that I'm not a linguist, nor can I read or write a word of Mandarin Chinese, and will happily stand corrected. This is just what I've picked up from reading books about the history and development of writing.

OskarS··on Libghostty is coming
You know, I can't remember ever doing this in a terminal. Not because it doesn't sound useful (it sounds VERY useful), it just sort-of never occurred to me as a thing you could do. It's just muscle memory at this point to rerun the command with a pipe to a pager and search there.
OskarS··on 40k-Year-Old Symbols in Caves Worldwide May Be the Earliest Written Language
All true written languages are phonetic to some extent, even though they may not be alphabetical the way English is. Chinese characters have phonetic components indicating tone and pronunciation, Egyptian hieroglyphs are largely syllabic, Norse runes are alphabetic like English. In Chinese and Egyptian, there are purely non-phonetic symbols representing ideas (and other things like determinatives), but most have some kind of phonetic meaning (this is my understanding at least).

There's a spectrum of how phonetic a language is, where Finnish is on one end (sounds very closely align with spelling) and Chinese characters on the other, but all written languages are phonetic to some degree.

OskarS··on 40k-Year-Old Symbols in Caves Worldwide May Be the Earliest Written Language
No. Linguists make a distinction between "writing" and "proto-writing". Generally speaking, proto-writing involves using abstract symbols for some particular use case, historically it was common for accounting. You draw a sheep and put five tally marks next to it to indicate you have five sheep, that kind of thing. Proto-writing is considerably older than true writing, among the earliest widely known examples would be clay tokens known as "bulla" [1] from at least 8000 BCE

Proto-writing can be very complex (I remember reading a book where a linguist calls mathematical notation "proto-writing"), but it's not "true writing" until it's capable of communicating essentially any idea you can express in spoken language (it's hard to write "I miss my cat Whiskers" in mathematical symbols) in at least a partly phonetic way (all true writing languages are phonetic to some extent). The earliest examples of that is Sumerian cuneiform and Egyptian hieroglyphs from around 3000 BCE. Whatever this discovery is, it's not true writing.

[1]: https://en.wikipedia.org/wiki/Bulla_(seal)

OskarS··on Calculator Forensics (2002)
I would assume most basic calculators use regular floating point circuits, and then just round aggressively for the display.
OskarS··on Calculator Forensics (2002)
Couldn't resist checking what math.h does for floats and doubles on godbolt, it returns slightly above 9, but curiously not exactly equal to any answer in that list [1]. Maybe not that surprising, these transcendental functions are always iffy in the last digits.

[1]: https://godbolt.org/z/dK85Eq8r6

OskarS··on Solving a wooden puzzle using Haskell
It is in the book, it’s a big part of 4B, which was published in 2022. The main topics are backtracking, exact cover using Dancing Links and satisfiability. It’s my favorite volume of the whole bunch.
← PreviousPage 3 of 34Next →