News for hackers. Stuff that matters.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by klyrs on Saturday December 31, 2022 @02:08PM (#34199621)
> But if you have ten thousand cuts you’re probably doomed. And those don’t show up cleanly in a flame graph.

I am reminded of the lovely nanosecond/microsecond talk by Grace Hopper. If your code does a little big of setup and then spends all of its time in a single hotspot, fine. But if your code is full of microsecond-suboptimal speed bumps, you can probably hide your hotspot altogether. And a flat-ish flame graph looks fine: nothing stands out as a problem!

It's valuable to do micro-benchmarks, not just to hone your optimization skills, but to learn optimal patterns in your language of choice. Then, when you're "in the zone" and laying down new code, you just do the optimal thing reflexively. Or, when you're reviewing or rewriting something, those micro-hotspots jump out and grab your attention.

There's a reason that ancient software running on ancient hardware is way more responsive & snappy than what we have today. Laziness.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by Dylan16807 on Saturday December 31, 2022 @02:34PM (#34199858)
> There's a reason that ancient software running on ancient hardware is way more responsive & snappy than what we have today. Laziness.

Laziness in terms of using entirely inappropriate algorithms, sure.

Laziness in not microbenchmarking minutia? It shouldn't be. There's a limit on how much that can hurt you. I would say much less than a factor of ten, but let's go with 10x just for argument's sake. If you have a CPU that's 500x faster, and use easy code that's 10x slower, you're doing just fine. This is not the problem with modern unresponsiveness.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by klyrs on Saturday December 31, 2022 @02:58PM (#34200121)
When I rewrite python code in C, I often hit 1000x speedups, and sub-100x is rare. And that's line-for-line. When I fix an accidentally-quadratic issue, for example, I've seen speedups in the billions without even changing the language.

People have lionized Knuth's quote about premature optimization, and used that to ignore performance issues across the board. Since the early '00s, we have not seen a 500x improvement in CPU speed. It's less than 2x on frequency, and let's say 8x on core-count for most users (which doesn't help your single-core lazy programmer). In my experience, programmers will make projections based on a 500x-faster processors that will never arrive, because it's easier than honing their skills and keeping them sharp. And even if these magical THz-frequency chips arrive, if you have three layers of 10x slowdowns, you're back down to GHz.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by josephg on Saturday December 31, 2022 @03:33PM (#34200438)
This has been my experience too. I wrote a text crdt last year which improved automerge’s (then) 5 minute runtime. My code currently takes 6ms to do the same work.

Automerge’s design assumed this stuff would always be slow, so they had this whole frontend / backend code split so they could put the expensive operations on worker threads. Good optimizations in the right places make all that complexity unnecessary. The new automerge is shaping up to be simpler as well as faster.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by Dylan16807 on Saturday December 31, 2022 @04:29PM (#34200975)
> When I rewrite python code in C, I often hit 1000x speedups, and sub-100x is rare. And that's line-for-line. When I fix an accidentally-quadratic issue, for example, I've seen speedups in the billions without even changing the language.

And neither of those is a microbenchmark thing, which is kind of my point. I'm surprised language would hurt that much, but that's enough to break things on its own without any layering.

> Since the early '00s, we have not seen a 500x improvement in CPU speed. It's less than 2x on frequency, and let's say 8x on core-count for most users (which doesn't help your single-core lazy programmer).

I don't think people are talking about 2004 when they talk about the responsiveness of ancient software on ancient hardware. I interpret that as more like an Apple II. But instructions per clock have also gone up a lot since the pentium 4 days, and having more than one core in your CPU has a huge impact even for single-threaded programs.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by klyrs on Saturday December 31, 2022 @04:50PM (#34201134)
> And neither of those is a microbenchmark thing, which is kind of my point. I'm surprised language would hurt that much...

The point I'm making here is that every line matters -- not just the hotspots. If you're suprised that language can have that much impact, perhaps it's time to learn a bit about performance issues that you're being dismissive of?

> I don't think people are talking about 2004 when they talk about the responsiveness of ancient software on ancient hardware.

No, I was responding to your mention of a 500x improvement in hardware. That pipedream ended in the early 00s, and people still talk like Moore's law will absolve their inattentive coding practice. And that felt fine in the decades we went from kHz to GHz, but it's unacceptable today.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by Dylan16807 on Saturday December 31, 2022 @05:00PM (#34201207)
> The point I'm making here is that every line matters -- not just the hotspots.

That depends on how it would have performed if you only transformed the hottest 10% into C.

But I was mainly responding to the idea that micro-optimizations are needed to keep general software snappy, and I don't think they are. If one language is that much faster, that's not micro-optimization.

> No, I was responding to your mention of a 500x improvement in hardware.

What do you mean "No"? I was talking about current hardware being 500x faster than 1988 hardware, which it is. If that's not what you meant by "ancient software on ancient hardware", fine, but that's what my 500x was talking about.

> people still talk like Moore's law will absolve their inattentive coding practice

I'm not trying to excuse inattentive coding. I'm trying to say certain kinds of attention are important and others aren't.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by imtringued on Sunday January 01, 2023 @09:27AM (#34206482)
Python is easily 200x slower than C for equivalent code. The reason why Python is usable is because it uses a lot of C libraries that do the heavy lifting.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by naasking on Saturday December 31, 2022 @04:58PM (#34201189)
> And a flat-ish flame graph looks fine: nothing stands out as a problem!

If your program is still slow, that would also indicate that everything is a problem, ie. the ten thousand cuts. Start optimizing at some obvious spots and then see what happens.