News for hackers. Stuff that matters.
Re:Revoking certain certificates on March 4 by jandrese on Tuesday March 03, 2020 @03:22PM (#22478368)
Won't the pointer also be hot in cache in this case? I only ask because it seems to me like excessive data copying (and cache eviction) is a major source of slowness in modern programs. People are churning their cache to pieces by copying the world for every function call.

It's fine as long as your entire program fits neatly in cache, but once you exceed the cache size performance goes to hell because you force loads of misses of slightly-older data by constantly copying your working data.

Re:Revoking certain certificates on March 4 by comex on Tuesday March 03, 2020 @08:49PM (#22480519)
> Won't the pointer also be hot in cache in this case?

Depends on the situation; the parent was somewhat vague.

As one example, suppose you've previously created a `struct foo`, but you haven't accessed it in a long time; then fetching any of its fields will probably be a cache miss. But if it contains a pointer, fetching data from that pointer will probably be a second cache miss – which can't even be started until the first one completes, because the CPU doesn't know what the pointer is. If `struct foo` contains the data directly, there's a good chance it all fits in a single cache line (typically 64 bytes). But even if it's split across, say, two cache lines, the CPU knows which cache lines need to be accessed, so it can send off the second request without waiting for the first one to complete.

That said:

- Strings are variable length, so they usually can't be stored in place anyway, although some languages/frameworks have "small string optimization", meaning that sufficiently short strings are stored in the space that would otherwise be used for the pointer and length.

- In general, Swift is hardly a good role model when it comes to performance. :p

Re:Revoking certain certificates on March 4 by londons_explore on Tuesday March 03, 2020 @06:26PM (#22479738)
Most importantly, programmers of the 2020's shouldn't be making these decisions.

Wether you choose to pass by reference or copy, that should just indicate your desired semantics. The underlying compiler can decide if it's really worth making a copy or not.

Sadly most compilers won't elide out most unnecessary copy operations, even when performance would be improved to do so.