3 ms·
> The production Rust code I did see, is passing copies of objects left and right. You might be surprised how fast memcpy() is in practice on modern hardware.
by munificent 2y ago
> The production Rust code I did see, is passing copies of objects left and right.
You might be surprised how fast memcpy() is in practice on modern hardware. It's worth sitting down and writing a little C program that moves memory around and does some other stuff to get a feel for what the real world performance is like.
- sroussey 2y agoI too come from a time of worrying about memory access patterns and usage (pre virtual memory in hardware), so my initial reaction is like the parent comment, at least instinctively. And yes, memcpy is fast, but I would not use a little program to convince myself. You will end up with stuff in CPU caches, etc, which will give you a very incorrect intuition. Better to take a large program where there is a base factory and make some copies there or something and see how it affects things. That said… for most businesses these days, developer time is more expensive than compute time, so if you’re not shipping an operating system or similar, it simply doesn’t matter. And an optimizing compiler could do something like copy on write, and make much of the issue moot. I had a brief period of time designing a simple CPU and it’s made everything since turn my stomach a little bit.
- munificent 2y ago> I would not use a little program to convince myself. You will end up with stuff in CPU caches, etc, which will give you a very incorrect intuition. I did not say a program that works with little memory, I said a little program. :) void main() { malloc(10000000); } This is a very little program, but it's memory will certainly not all fit in the cache.