News for hackers. Stuff that matters.
Re:C performance mystery: delete unused string constant by MaxBarraclough on Thursday June 25, 2020 @04:56AM (#23638410)
> in real systems a small simple loop will perform better due to icache pressure

Do you have a source for this? Seems surprising GCC would leave such low-hanging fruit. G++ makes the effort to reduce std::copy to a memmove call when it can, or at least some of the time when it can (or at least, it did so in 2011). [0]

Related to this: does GCC treat memcpy differently when it can determine at compile-time that it's just a small copy?

[0] https://stackoverflow.com/a/4707028/

Re:C performance mystery: delete unused string constant by Gibbon1 on Thursday June 25, 2020 @04:23PM (#23645237)
Problem is superscalar processors the correspondence between number of instructions and speed breaks down. Partly because the processor does it's own optimization on the fly and can do multiple things in parallel.

A programmer should be careful about second guessing the compiler. And a compiler should be careful about second guessing the processor.

Re:C performance mystery: delete unused string constant by MaxBarraclough on Friday June 26, 2020 @04:42AM (#23649967)
I'm not sure if you're implying this is premature optimisation. It isn't.

It's a performance-sensitive standard-library function, the kind of thing that deserves optimisation in assembly. It's also the kind of problem that can be accelerated with SIMD, but that necessarily means more complex code. That's why the standard library implementations aren't always dead simple.

Here's a pretty in-depth discussion [0]. They discuss CPU throttling, caches, and being memory-bound.

[0] https://news.ycombinator.com/item?id=18260154

Re:C performance mystery: delete unused string constant by jeffbee on Thursday June 25, 2020 @11:55AM (#23642095)
Only personal experience. If you look at the memcpy in llvm's libc, it was contributed by Googlers who share my experience and perspective.