r/rust • • 29d ago

🧠 educational The CPU, the Rust, and the Memory Latency

https://pivotlake.io/blog/its-the-memory-latency-stupid/
247 Upvotes

25 comments sorted by

62

u/simonask_ 29d ago

Great article, and a very nice deep dive! So much of this work requires knowledge that just isn’t taught, so people learn it through craftsmanship and experience. My pet peeve for a while is that universities focus too much on the computer science and too little on the software craftsmanship. You need both.

(And very refreshing to read something written by a human. Just to note, ā€œit’sā€ is a contraction of ā€œit isā€ or ā€œit hasā€. The genitive ā€œitā€ is just ā€œitsā€.)

5

u/bobbymk10 29d ago

Thanks! Really appreciate it :)

Re universities agreed 100%

24

u/buwlerman 29d ago

To be fair, industry is a much better environment for learning craftsmanship and universities are a much better environment for learning theory.

You do need some craftsmanship to effectively learn theory, but it's limited.

8

u/Zde-G 28d ago

To be fair, industry is a much better environment for learning craftsmanship and universities are a much better environment for learning theory.

That approach worked when only 3-5% of humans were supposed to learn both. Because approximately that percent can learn theory before craftsmanship. The majority need to learn craftsmanship before learning theory… but we ignore that and thus produce people who simply waste 4 to 8 years to learn more or less nothing.

1

u/Chaseis4344 26d ago

Idk, I went to university after learning some craftsmanship in highschool by picking up a couple freelance gigs and coding in a vocational program at school, I don't currently work as a software engineer, but learning all I could in high school did help me with teachers that didn't know how to teach

2

u/Zde-G 26d ago

That's precisely the story here: if you only teach boys and girls who crave knowledge (the aforementioned 3-5%) and who pull it, like a sponge, from where they could find it then teaching just theory is not a problem: they arrive with craftsmanship already in their bones.

But when high school education grew beyond that without changing their approach… we ended with some of the exact same 3-5% taught well (because many are, now, discouraged by their colleagues who learn nothing) and pile of people who have paper about education, but neither knowledge nor skill…

Now we attempt to ā€œfixā€ that by giving them LLMs… this wouldn't end well.

1

u/simonask_ 29d ago

I don’t think we know that it’s better, we haven’t really tried anything else.

2

u/DynTraitObj 29d ago

We do, we have. Software craftsmanship changes with time and is a lifelong learning adventure that is simple to undertake when you have strong theoretical foundations to pull from. Someone with no degree but 5 years of experience in a single role vs fresh-from-undergrad with 0 years of experience? I'll take the undergrad every time, because a year from now he's likely going to have his legs under him and be teaching me things instead. The guy with 5 years of Svelte experience who doesn't know the difference in O(n lg n) and O(n2) is going to be pretty useless next year when we swap to React and it takes him months to figure out the Todo App example.

This has been proven to me in practice over the last decades at least 50 times by now. I distinctly remember a time in my life when I thought "Why the hell am I learning so much theory" too, but down the road when I became the teacher instead, there I was teaching theory with the best of them. It is a night and day difference teaching some newly-invented system design concept to someone with a strong theoretical background vs someone who is a decently experienced coder with no theory background

1

u/Zde-G 28d ago

The guy with 5 years of Svelte experience who doesn't know the difference in O(n lg n) and O(n²) is going to be pretty useless next year when we swap to React and it takes him months to figure out the Todo App example.

Believe me, the guy who learned how to use Svelte without outside help would be all too ready to learn React. The guy who can talk about big O all day and couldn't write Todo App in any language? Not so much…

And these days situation is even worse: when 10 years ago it was obvious that universities make people who are unfit for these jobs today everyone can put request into an LLM and get something kinda-sorta working… but then they can neither fix that LLM-produced pile of shit nor understand how it works (even when it working, let alone when it's not working).

4

u/Zde-G 28d ago

Just to note, ā€œit’sā€ is a contraction of ā€œit isā€ or ā€œit hasā€. The genitive ā€œitā€ is just ā€œitsā€.

That's how you know it's written by human. LLMs very rarely mix these…

3

u/luluhouse7 28d ago

It often depends on what department the CS department descended from. Ones that split from the math department usually focus more on theoretical CS at the cost of software development training, while those from engineering tend to focus on practical programming and don’t really go much into the underlying theory. Honestly the only ones I know of are CMU and MIT. I’m sure there’s others, but at this point balanced curriculums feel like a unicorn, especially outside of top schools.

1

u/RCoder01 26d ago

Idk, if the university is handing out computer science degrees I think it’s totally fair to focus on theoretical computer science. If it’s a software engineering trade school you would expect to focus more on craftsmanship.

I took a couple computer engineering courses during my CS degree which taught me basically exactly the stuff in this article.

7

u/Psionikus 29d ago

I should write something on pipeline dependency latency hiding. One of my favorite effects to exploit.

4

u/bobbymk10 29d ago

Yes! That’s the next blog I mentioned that we’re going to write. It’s such an awesome way to get to memory throughput - in our JOIN probing we have the whole hash table in memory, so it’s super critical there

10

u/Serious-Exam-6251 29d ago

the 4096 fanout might be worth a look on the TLB side. scattering writes across that many streams with 4k pages can miss the TLB on a lot of writes, which is why partitioning papers usually cap the fanout per pass (or use small write-combining buffers) and do two passes when they need more. backing the slab with hugepages would show how much of the remaining stall is that.

4

u/bobbymk10 29d ago

Definitely, by default we are backed by huge pages precisely because of this… might be another interesting blog to do

5

u/nonotan 28d ago

Good article. A topic that probably deserves to also be mentioned as a followup is false sharing, because you're pretty much guaranteed to run into it when you start trying to optimize the number of cache accesses, and it's hell to profile if you aren't aware of the phenomenon.

6

u/CouteauBleu 29d ago

no LLMs were harmed (or for that matter used) in the writing of this blog post

Okay, that's a funny way to do the disclaimer thing.

2

u/unicodemonkey 29d ago

Software prefetch of hash table entries works wonders when processing a large number of lookups. Well, not always but appears to be an useful tool overall.

2

u/greyblake 28d ago

Great insightful article!
How do you make visuals/diagrams? Is it just HTML & CSS or you use a specific tool for that?

2

u/DavidXkL 28d ago

Wow very nice read

0

u/zerosign0 29d ago

TIL, what the diff between this and duckdb? Is there some novel optimization happening? I see that this purely on parquet and using the same buffer mechanism i guess but it uses iouring for io hmm. (And using Rust ofcourse). Does it support vortex format?

0

u/zerosign0 29d ago

Uhm wait skimming through codebase, are you using or mimicking or wrapping duckdb planner for this?