HNHacker News
TopNewBestAskShowJobs

OskarS

8,399 karma · joined September 4, 2016

submissionscomments
OskarS··on Using the mold linker for fun and 3x-8x link time speedups
mold seems very cool! The design notes [1] are fabulous, exactly the kind of documentation I look for for stuff like this. This part, in particular, is genius:

> As we aim to the 1-second goal for Chromium, every millisecond counts. We can't ignore the latency of process exit. If we mmap a lot of files, _exit(2) is not instantaneous but takes a few hundred milliseconds because the kernel has to clean up a lot of resources. As a workaround, we should organize the linker command as two processes; the first process forks the second process, and the second process does the actual work. As soon as the second process writes a result file to a filesystem, it notifies the first process, and the first process exits. The second process can take time to exit, because it is not an interactive process.

Never heard about this trick before, but it's the rare combination of "genius" and "obvious in retrospect".

[1]: https://github.com/rui314/mold/blob/main/docs/design.md

OskarS··on C library for multiple-precision floating-point arithmetic with correct rounding
Because it’s a cool piece of technology, and this is a place for computer professionals? if you can’t appreciate GNU MPFR, you might be hanging out at the wrong place
OskarS··on Senate Bill S6486D Establishes a moratorium on cryptocurrency mining
Washing machines wash clothes, they provide value to the world. And they are subject to plenty of government regulation.
OskarS··on Senate Bill S6486D Establishes a moratorium on cryptocurrency mining
Excellent news! The energy consumption required by proof-of-work blockchains is simply unacceptible, and it’s perfectly appropriate to adress it using new laws. Hopefully other states and countries will follow suit.
OskarS··on Monterey’s Finder Find memory leak may not be fixed
Yeah, I agree, it's a shame that there isn't a better mechanism to pay for CLI software. I think a lot of developers would just refuse non-open source CLI software, but that really shuts down what could be a healthy market. Don't know what the solution would be though ("GitHub sponsors" don't seem to be it...)
OskarS··on Monterey’s Finder Find memory leak may not be fixed
Terminal workflows are very much not for everyone. Many people are happy to pay a few bucks for a nice and friendly GUI application. It's not such a bad thing that people are willing to pay for software, as it is, in fact, the way many of us make our living.
OskarS··on Uniformly Sample Points in a Disk
> What costs more, generating a random number and maybe a second or a random number and a sin/cos

You’re adding a very unpredictable loop branch and a bunch of data dependencies doing that. For GPUs (and maybe even CPUs), the sqrt way is almost certainly faster.

OskarS··on Common libraries and data structures for C
> The patterns I knew and saw with std::optional usually returned "new something", but yeah, you can return a copy too if the class fits in the stack.

Oh, fer crying out loud... It DOES NOT return a copy, it constructs it directly in place. This is called "copy elision" (also known as "return value optimization", or RVO), and has been done by compilers for three decades, and is actually mandated behaviour in modern C++. I don't know where you saw these examples, but you would never use operator new with std::optional: it takes a value, not a pointer.

You have a very annoying style of being wrong about absolutely everything you say, and then acting superior about it when people call you on your bullshit.

OskarS··on Common libraries and data structures for C
It's that amount of lines UNCOMPILED. Of course uncompiled code wouldn't fit in 64kb of flash (the compiler wouldn't fit either, you know). Compiled, std::optional takes up essentially no overhead, basically the same as if you're returning a single bool along with your object.

> This is practical with an efficient heap allocator (which I might not have). What happens if I want a scoped (on stack) instance of a class?

There is absolutely no reason to do a heap allocation for a factory function in modern C++ (or even relatively ancient C++, in fact). The fact that you would think so indicates you simply don't know C++ at all.

Tell me, where in these six lines do you see a heap allocation? Where in the total of 6 instructions this compiles down to do you see anything that couldn't run in any embedded environment? Tell me how these six instructions wouldn't fit inside your 64kb of flash:

https://godbolt.org/z/rErWPbbbx

And again, EVEN IF you're so religiously and irrationally opposed to using std::optional, you can just return a default-constructed object and an extra bool indicating successful construction. I don't know why you would considering you could just return an optional, but whatever, you can do it that way if that's what you prefer.

You're just wrong about this stuff, and it's this kind of lazy, uniformed criticism of C++ that really rubs me the wrong way. If you wanna use C, use C! Nobody's stopping you, it's a fine language. Just leave the C++ discussions to the people who actually know what the language is.

OskarS··on Common libraries and data structures for C
Yeah, checking return codes is a thing you NEVER have to do in C...

The "exceptions are evil, but without exceptions you can't fail a constructor!" is a really irritating canard when it comes to C++. First off all, the terribleness of exceptions is way overhyped, but even if you do want to avoid them, this is not a problem: just use a factory function instead of a constructor and return a `std::optional` (or a default-constructed value and an error code if you want to avoid `std::optional` for some weird reason).

I like pure C a lot and it definitely has a place in areas like embedded. But this kind reflexive disdain for C++ using uninformed arguments is really tiresome. C++ is fine.

OskarS··on Advanced techniques for reducing Emacs startup time
I just use recentf for that. My buffer list contains everything in the recentf (this works with buffer list replacements from both Helm and Ivy). Makes it trivial to open up any file I've had open before.

Opening all buffers you've ever edited sounds nuts to me. What if one of the files you edited was a 10 gb log file or whatever?

OskarS··on Friendlier SQL with DuckDB
One of SQLite's most appealing aspects to me is using it as an application file format, as described in this article: https://www.sqlite.org/appfileformat.html

How does DuckDB compare in that aspect? Does it have the same kind of guarantees of robustness, incorruptibility and performance (especially reading/writing binary blobs) that SQLite does?

In any case: DuckDB looks great, nice work! Good to have more players in this space!

OskarS··on Donald Knuth was framed (2020)
It's not a million miles of what Knuth was talking about, I think he'd be pretty happy to call those kinds of notebooks literate programming.
OskarS··on Bunnymark GL in Jai – 200k sprites at 200fps [video]
> All the CPU has to do is update that mmap'ed buffer with new position information

Doesn’t even have to do that, this is child’s play for a compute shader. The CPU can go take a 16 millisecond nap and let the GPU do all the work.

OskarS··on Practical bruteforce of military grade AES-1024 (2021) [video]
Yep, totally, it's a big red flag. Another term like that when it comes to software is "patented technology" (or "algorithm", or "software", or whatever). Instant turn-off.
OskarS··on Counting set bits in an interesting way
I'm quite fond of this classic for popcount [1]:

    int popcnt(unsigned int n) {
        int p = 0;
    
        while (n) {
            p++;
            n &= n-1;
        }
    
        return p;
    }
But it has a branch in it, so I don't know if it's competitive with the "simple" version of just counting the ones or this version, even though the loop should run fewer iterations. Obviously the real answer is to just use the compiler intrinsics for this, but what fun is that?

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

OskarS··on The bottom is dropping out of Netflix
The thing I find interesting with Netflix is how much they spend on content and what a terrible rate of return it has. Look at Apple TV+, they're absolutely TINY compared to Netflix in both library size and money spent on new production, but they have arguably more hits than Netflix. Like, since when has any drama on Netflix been as buzzy or as good as Severance on Apple TV+? When was the last time they had a comedy success like Ted Lasso?

They have a couple of things that are very good (including Russian Doll, which is better than the article gives it credit for). But it's the ratio the that's troubling: the value of [good shows] / [shows produced] is absurdly much lower for Netflix than for Apple TV+, HBO Max or Disney+. All their spending seems to result in is endless mediocre True Crime documentaries that try recapture the magic of the first season of Making a Murderer, and the occasional golden nugget you binge in a weekend.

The article makes a big deal of the binging thing, and I agree it's a terrible model compared to weekly releases. But I feel like Netflix's real problem is that they just don't make enough good stuff.

OskarS··on Rustaceans at the border
Indeed. The comment cited in the article is pretty stunning:

> Other crates that I'd like: anyhow, bincode, byteorder, log, once_cell, pin-project, rand, serde, slab, static_assertions, uuid plus some more esoteric ones.

This makes Rust devs look infantile, with no real understanding of what it means to develop for the kernel. Or what it takes to develop security and performance critical software of any kind, frankly.

OskarS··on Xor swap trick and add/sub swap trick (2010)
The best way to do this in C++ is using std::bit_cast, which unfortunately only became available in C++20. Before that, you have to memcpy. That works just fine, but the syntax is a bit clunky and it doesn’t work in constexpr contexts, which is why std::bit_cast was introduced.

Compilers will optimize all of this to the same machine code.

OskarS··on Jd
Yeah, exactly: there are tradeoffs to both models, neither is strictly superior. You would never want to do aggregates on addresses anyway, so that advantage is out the door. You do, however, want to very easily index a table of addresses, so you could quickly look them up for a particular user, which a columnar database is (arguably) worse at. BigQuery, in particular, does not use indexes at all.

(EDIT: I guess you do might want to do aggregates on addresses, actually. "How many customers do we have in NYC?", that kinda thing.)

OskarS··on Jd
> Ofcourse that data has to be read from disk. Well, for simple or aggregate queries he may gain performance.

Lets say you want to access 2 columns out of 100 in a particular table. In a row-oriented database, you have to read the full rows off the disk, which means that you have to read 98 pieces of data off the disk that you have no use for, a total waste of I/O. In a columnar database, you don't have to do that, you just read off the relevant columns. This is VERY similar to the "array of structs"/"struct of arrays" argument in gamedev (and related high performance fields), it's the same kind of tradeoff: slightly more complicated data layout traded in for much more efficient reads.

In addition: if you have a columnar database, you can employ compression in a much more efficient manner. If you have 10 million rows with the same (or very similar) data in a column, you can compress that to a fraction of the size. This messes with indexes, but it's often worth it because it VASTLY speeds up aggregate calculations.

Row-based and column-based databases have different tradeoffs and advantages, and it's not quite as clear-cut as the article makes it seem. But it's certainly no April fools joke: columnar databases (for many tasks, particularly aggregates) can vastly outperform row-oriented databases. This is why Google BigQuery is columnar, for instance. Another good example is kdb+ (which this is clearly based off of), which is widely used in places which value quick time-series aggregates (Wall Street, being the obvious example).

The article is a bit over the top and one-sided, but it doesn't say anything that is particularly controversial. You might wanna read up on columnar database systems: https://en.wikipedia.org/wiki/Column-oriented_DBMS

OskarS··on Rustc_codegen_GCC can now bootstrap rustc
64 cores, and it takes 5 minutes? That’s… not awesome. Most people do not have 64 (presumably high performance) cores lying around for the purpose of building dependencies.
OskarS··on The hunt for the M1’s neural engine
This is slightly beside the point, but those stack traces are C++ functions. I was pretty surprised by that (though, granted, I don't know anything about macOS internals). I would have expected either pure C for the kernel, or maybe Objective-C if they wanted a higher level language. They don't really have any C++ in their operating system APIs, right? Like, if you interface with Core <Whatever>, isn't that all C, Objective-C and Swift? Is there a lot of C++ in the macOS kernel/userspace?
OskarS··on Stackit: Cloud and Colocation
Yeah, that was my issue as well. Grammar aside, that sentence is so full of corporate-speak as to be virtually meaningless. It might as well just be in German.
OskarS··on Please put units in names
"It's annoying" is a pretty good reason. If you don't mind function names like that, go become a Java Enterprise programmer, see how you like it after a few years.

In addition: it's the wrong solution to the problem. The units shouldn't be baked in to the function definition, just the type of quantity. You should be able to do both:

    setSpeed(10 m/s)
and

    setSpeed(45 km/h)
Which you can do in many languages. In fact, time functions in C++ work exactly like this. If you want to suspend a thread for 10 seconds you do

    std::this_thread::sleep_for(10s);
but if you want to suspend it for 5 milliseconds, you do

    std::this_thread::sleep_for(5ms);
And if you just supply a unitless number, it's a compiler error.
OskarS··on Down the mechanical keyboard rabbit hole
You don't really need those keys for that, there are almost always various chords that do that. macOS, in particular, has "Emacs-light" keybindings in most edit fields: Ctrl-A goes to the beginning of a line, Ctrl-E goes to the end, Alt-Backspace erases a word, etc. Of course, if you use Vim-style keys, you use normal mode for all that stuff.

In general though, custom mechanical keyboards have firmware that can be programmed with "layers": hold down a certain key (or toggle) and layers get activated which changes the meanings of keys. This is the way those very minimal keyboards (which doesn't even necessarily have a number row) can work for daily use. If you want the keys badly, just program your firmware appropriately.

OskarS··on The only flag of the world that is shredded by design
I bet this flag is the bane of the existence of some developer maintaining a flag database or something. Like, having to rejigger the entire schema to fit this thing in, telling war-stories to the new devs coming in: "Kid, you don't even know how weird flags get...". At some point he'll write an article that's like "Falsehoods programmers believe about flags", and this will be the example for like seven of the points.
OskarS··on I wrote the least-C C program I could
Did not even think about that :) Just so used to thinking of enums like that as opaque values.
OskarS··on I wrote the least-C C program I could
Hey, even an article written by Walter, that's a fun coincidence! :)

This is slightly different than the form I've seen it, but same idea: in the version I've seen, you have a special file that's like "enums.txt" with contents like (warning, not tested):

    X(red)
    X(green)
    X(blue)
and then you write:

    typedef enum { 
        #define X(x) x
        #include "enums.txt"
        #undef X
    } color;

    const char* getColorName(color c) {
        switch (c) {
            #define X(x) case x: return #x;
            #include "enums.txt"
            #undef X
        }
    }
Same idea, just using an #include instead of listing them in a macro. Thinking about it, it's sort-of a compile time "visitor pattern".
OskarS··on I wrote the least-C C program I could
You could probably do an either or thing: "You can drop the parentheses if you use braces. But you can't drop both". Though you're right, this is why it'll never happen.

Basically, C had a choice of eliding the parentheses around the condition or the braces around a single-statement block, and they chose the braces. With a half-century of hindsight, that was probably the wrong choice.

← PreviousPage 14 of 34Next →