This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix performance break-down in gcc.c-torture/unsorted/dump-noaddr.c

Hi Jeff,

as you know, this test case takes too long to complete if the test suite is run with
this command line:

MALLOC_PERTURB_=237 make -k check

The reason was found in libcpp/charset.c, where a reallocation is done one byte at a time.

It seems to be in the macro expansion of this construct:

#define t16(x) x x x x x x x x x x x x x x x x
#define M (sizeof (t16(t16(t16(t16(t16(" ")))))) - 1)

libcpp is calling realloc 1.000.000 times for this, resizing
the memory by just one byte at a time.
And the worst case of
realloc is O(n), so in the worst case realloc would have
copy 1/2 * 1.000.000^2 bytes = 500 GB of memory.

With the change that you suggested, we increase the memory allocation by 25%, and now
the complete test suite gives exactly the same results with or wihout MALLOC_PERTURB_ .

Boot-strapped and regression-tested with and without MALLOC_PERTURB_
Ok for the trunk?


Attachment: patch-libcpp.diff
Description: Binary data

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]