Live data from Hacker News

What Every Programmer Should Know About Memory (2007) [pdf]

akkadia.org

91–100 of 101 posts

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#91
post #17

Earlier quoted context omitted.

Indeed, there are a limited number of hard-hitting topics that are definitely must-haves: * Rough latency timings * Caching * Prefetching * Sequential vs. random access * N-dimensional layouts (row/column major and arbitrarily strided) * Design of cache-oblivious algorithms * SIMD-able access patterns * False sharing * Instruction cache & code size * Branch prediction and speculative execution I'd be curious to hear…

Again, you say these are "must haves." But in the real world of software, none of these would make any difference to most of the software being built today, much of which is being build in higher level languages for web applications/web sites/microservices etc. Let's say someone is building a micro-service in C#.Net. Why would any of this stuff matter to them? The company cares about features and moving forward quick…

"most of the software being built today"

"web applications/web sites/microservices"

The world is bigger than you think it is. There could be more code in making a single AAA videogame than in the entire Amazon infrastructure.

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#92
post #27

Interesting that in 2007 he thought FB-DRAM was going to win. That seems to have been about the time it dropped dead.

Right, also about NUMA:

> It is expected that, from late 2008 on, every SMP machine will use NUMA.

Outside servers, still not happened.

They are not that exotic anymore and are no longer exclusive to very expensive servers, e.g. Threadripper 2920X is a $650 CPU, but market penetration is still low.

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#93

Earlier quoted context omitted.

The referenced work talks about floating point errors that both computer scientists and field engineers need to avoid. Many folks in both camps screw up on floating point code without such guidance. So, at least that part is potentially helpful. You just proved their point about how you'd reply, though.

Proved their point? Their point didn't make much sense. What actual engineers NEED to know about floating point numbers could be put on a single A4 page. It doesn't have to be 50 pages, where many of those pages are full of equations that 99% of engineers don't understand. My point is, because you seem to have trouble grasping this. Most real-world programmers, working at startups or bigger companies, making their WP…

"Proved their point? Their point didn't make much sense."

"My point is, because you seem to have trouble grasping this, ..."

Ha-ha, the irony.

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#94
post #60

Earlier quoted context omitted.

> I'm not saying it's not interesting, but it's not going to change how I write my for-loops and if statements or make calls to BigTable, etc. You might be surprised at how much changing your for loops can be when accessing matrix data. for(int i=0; i Test that out, and you'll see a major performance improvement. ----------- If someone is writing high performance code, the #1 goal is to be able to read your profiler'…

I have to admit, I was skeptical but my complier did pick SIMD for the second and not the first and it did make a huge difference. % cat t.c #include #include #include double get_time() { struct timeval t; struct timezone tzp; gettimeofday(&t, &tzp); return t.tv_sec + t.tv_usec*1e-6; } int blah[SIZE][SIZE]; int whatever() { static int i=0; return ++i; } int main() { double t0 = get_time(); for(int i=0; i 2.8G Core i7…

Now you could try to time it with -fno-tree-vectorize or whatever gcc uses nowadays. You might be surprised again :)

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#95
post #35
post #28

Earlier quoted context omitted.

Because knowing your craft is important? Besides, if you don't find this interesting why become a programmer in the first place

There's a lot to learn about this craft, and people have to prioritize - knowing algorithms & data structures is more immediately useful compared to, say, knowing what scratchpad memory is. If I spent my time learning every detail about every system underpinning every abstraction, I would literally be 70 years old by the time I started writing code. > Besides, if you don't find this interesting why become a programme…

But learning algorithms and data structures literally requires you to know about memory on a pretty low level. As I'm sure you know, a lot of algorithms and data structures that are theoretically equal can be vastly different in practice in no small part because of how they use memory.

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#96

Earlier quoted context omitted.

> I'm not saying it's not interesting, but it's not going to change how I write my for-loops and if statements or make calls to BigTable, etc. You might be surprised at how much changing your for loops can be when accessing matrix data. for(int i=0; i Test that out, and you'll see a major performance improvement. ----------- If someone is writing high performance code, the #1 goal is to be able to read your profiler'…

If I saw that code at my company, I'd ask why someone building a rest api for web-services had to iterate through a 10000*10000 2D array while calling a method of every single cell. This isn't a use case I've seen in my 10 year career thus far. Also, you have to understand that saving 1 or 2 milliseconds isn't important when compared to getting software built faster. For the typical use case, optimizing a for-loop li…

I've seen the code written by a Python web-programmer that for a given binary matrix of teams and tournaments produced top 10 rivals for each team where rivals are defined as teams that have picked the same tournaments to participate as your team.

There are tens of thousands teams and thousands of tournaments and his code was taking two days to precalculate the results for every team.

Written with minimal understanding of how slow the memory is, the new code takes less than a minute. There was no point of optimizing it further, the algorithmic changes were enough.

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#97

For an accessible talk about the real-world implications of this, I enjoy watching Mike Acton's CppCon talk "Data-Oriented Design and C++": https://www.youtube.com/watch?v=rX0ItVEVjHc

I routinely re-watch this talk. It always gets me back in the right mindset.

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#98

Is this title and content supposed to be ironic? I quickly perused the article and I think this link should be renamed "What 99.9% of programmers don't need to know about memory." I've managed to go from Associate to Principal without knowing 99% of what's covered in this document, and I'm struggling to understand why the average Java, C#, Python, Rust, programmer would need to know about transistor configurations or…

It’s fair game for a python/java/c# interview though! /s

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#99
post #94
post #60

Earlier quoted context omitted.

I have to admit, I was skeptical but my complier did pick SIMD for the second and not the first and it did make a huge difference. % cat t.c #include #include #include double get_time() { struct timeval t; struct timezone tzp; gettimeofday(&t, &tzp); return t.tv_sec + t.tv_usec*1e-6; } int blah[SIZE][SIZE]; int whatever() { static int i=0; return ++i; } int main() { double t0 = get_time(); for(int i=0; i 2.8G Core i7…

Now you could try to time it with -fno-tree-vectorize or whatever gcc uses nowadays. You might be surprised again :)

Yup yup. SIMD is a CPU-level optimization, but the problem (at size 10,000 x 10,000) is DDR4 memory-limited.

SIMD only really makes a difference at the L1 or L2 cache levels. Its a fancy micro-optimization that compilers do and can improve code speed in those cases...

But the "big" change, going from column-wise traversal into row-wise traversal, is the huge memory optimization that programmers should know about. It just so happens that SIMD-optimizations are also easier for compilers to figure out on row-wise traversal, so you get SIMD-optimization "for free" in many cases.

Re: What Every Programmer Should Know About Memory (2007) [pdf]

#100
post #38

Is this title and content supposed to be ironic? I quickly perused the article and I think this link should be renamed "What 99.9% of programmers don't need to know about memory." I've managed to go from Associate to Principal without knowing 99% of what's covered in this document, and I'm struggling to understand why the average Java, C#, Python, Rust, programmer would need to know about transistor configurations or…

I'm sure some programmers don't need to know this. For example an Erlang or Haskell programmer can't do anything about memory layout anyway, so this knowledge would be of no immediate practical use.

Not exactly. There's plenty of ways of looking at GC and controlling allocation and lifetimes in Haskell is definitely possible.

And when necessary the C FFI is useful to have to write small bits of code to take advantage of particular layouts and drive them from code. See [0].

[0] https://www.youtube.com/watch?v=b4bb8EP_pIE

Post reply on HN