by mjburgess · 3y ago · 0 comments
Ie., the next frontier is moving from RAM to cache, since CPUs are not going to get faster than programs are "already slow".
If you rewrite some OOP/Pointer-Machine-Model/RAM-Thrashing programs for modern CPUs, you can get 100-1000x speed-up.
The evolution in language design seems, then, to be about exposing more of the hardware to enable developers to target it effectively.
For a very simple comparison, I recently was testing a (poorly) custom built data-oriented Entity-Component-System for usage in games with a more typical "componentized" object approach. No multithreading or anything complicated.
On my system, the typical approach could generate about 1000 new objects and attach a single component in about 1 millisecond.
The data-oriented approach could generate about 100,000 new "objects" and attach a single component in about 0.5 milliseconds.
Same thing in the end, but one is roughly 200x faster in the same time frame. It's pretty stunning when you see stuff like this in benchmarks.
-----s.-ms.-us.-ns|----------------------------------------------------------
0.1 ns - NOP
0.3 ns - XOR, ADD, SUB
0.5 ns - CPU L1 dCACHE reference (1st introduced in late 80-ies )
0.9 ns - JMP SHORT
1 ns - speed-of-light
?~~~~~~~~~~~ 1 ns - MUL ( i**2 = MUL i, i )
3~4 ns - CPU L2 CACHE reference (2020/Q1)
5 ns - CPU L1 iCACHE Branch mispredict
7 ns - CPU L2 CACHE reference
10 ns - DIV
19 ns - CPU L3 CACHE reference (2020/Q1 considered slow on 28c Skylake)
71 ns - CPU cross-QPI/NUMA best case on XEON E5-46*
100 ns - MUTEX lock/unlock
100 ns - own DDR MEMORY reference
135 ns - CPU cross-QPI/NUMA best case on XEON E7-*
202 ns - CPU cross-QPI/NUMA worst case on XEON E7-*
325 ns - CPU cross-QPI/NUMA worst case on XEON E5-46*
|Q>~~~~~ 5,000 ns - QPU on-chip QUBO ( quantum annealer minimiser 1 Qop )
10,000 ns - Compress 1K bytes with a Zippy PROCESS
20,000 ns - Send 2K bytes over 1 Gbps NETWORK
250,000 ns - Read 1 MB sequentially from MEMORY
500,000 ns - Round trip within a same DataCenter
?~~~ 2,500,000 ns - Read 10 MB sequentially from MEMORY~~
10,000,000 ns - DISK seek
10,000,000 ns - Read 1 MB sequentially from NETWORK
?~~ 25,000,000 ns - Read 100 MB sequentially from MEMORY~~
30,000,000 ns - Read 1 MB sequentially from a DISK
150,000,000 ns - Send a NETWORK packet CA -> Netherlands
1s: | | |
. | | ns|
. | us|
. ms|
(https://stackoverflow.com/a/33065382)However,
0.001 ns light transfer in Gemmatimonas phototrophica bacteriae
biology has much more performant/optimized machines, therefore, yes, plenty of room for improvement in silico.It's not clear that organic solutions at that level can do programmable computational work, nor that their work is at all deterministic.
At best, it would seem the organic direction for computing will be about building robots rather than CPUs.
The quotation marks around organic are just there to point out that there is something wrong with the dichotomy organic (various pro/eu-karyotes from bacteria to humans)/inorganic (from thermostats to CPUs).
[1] Michael Levin: Anatomical decision-making by cellular collectives https://www.youtube.com/watch?v=Z-9rLlFgcm0
I could be wrong in the assumptions - but OP is talking about fitting stuff in CPU cache don't really see how that translates to your scenario.
- normalized, small/tight data structures
- data structures that are closely related in computational terms
- smaller interfaces and functions that tend to be more re-usable and general
- fewer if/else branches and more existence based branching via loops
- fewer "business level" generics, macros and similar abstractions, because you can dispatch easily via tagging to concrete types
- less code that "digs"/"drills" into data and more code that composes data
- generally a simpler (less coupled) end result
This all comes with a cost of having to do upfront design and exploration in order to decompose and lay out your data. And while it reduces the mental overhead of understanding the individual pieces of your program on a day by day basis, it might increase learning curve of seeing the big picture, especially at the beginning. So it is a tradeoff.
But I think it would be too dismissive to say that the programmer is doing compiler work here. It is design work, and it is unlearning some of the notions of how to structure programs that carried on since the 90's. Some of which are performance related and some of which are about sensible code structure.
Legit question, I have no idea about how this would behave.
I know, sounds crazy. Who’s gonna make such a drastic change to the industry?
Expanding the cache so everything fits in it is one way to achieve the performance uplift of cache hits, but cache is expensive compared to memory, and current cache sizes are tiny compared to RAM. If cache gets 50x bigger tomorrow, chips will get at least 10x as hot, power-hungry, and expensive.
[1] my understanding is that RAM and CPU processes are very different and it is hard to produce a chip with both features while remaining optimal.
Look into Apple’s unified memory.
> ... the available RAM is on the M1 system-on-a-chip (SoC).