On 11/11/17 19:14 +0100, Marc Glisse wrote:
Hello,

operator new can clobber memory, it is hard to teach the compiler otherwise since it is replaceable. Here I cache a couple values before the call to the allocator. I checked the result on this simple example:

#include <vector>
void f(std::vector<int>&v){ v.push_back(0); }

The patch does not affect the fast path where no reallocation is needed. Compiling with -O3 (everything gets inlined into f), I see a nice decrease in code size on x86_64

$ size old.o new.o
  text     data     bss     dec     hex filename
   462        0       0     462     1ce old.o
   376        0       0     376     178 new.o

Even at -O2 where _M_realloc_insert is not inlined, I get a slight decrease in code size (490 -> 470). On x86, that's 531 -> 519 (465 -> 387 at -O3).

I'm not going to modify every function like that, I just happened to be looking at this example for other reasons, and the size gain is larger than I expected, so I am posting the patch.

That's a nice improvement, OK for trunk. Thanks.

Reply via email to