[PATCH] Change MCTextAtom to use std::list instead of std::vector
Stephen Checkoway
s at pahtak.org
Tue Oct 15 15:28:14 PDT 2013
On Oct 15, 2013, at 2:39 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Tue, Oct 15, 2013 at 11:27 AM, Stephen Checkoway <s at pahtak.org> wrote:
>
>> Changing MCTextAtom to use a list instead of a vector reduces the memory
>> usage of running llvm-objdump -disassemble -symbolize -cfg ninja from 16 GB
>> to 9 MB.
>>
>> I believe the problem is that erasing elements from the vector doesn't
>> free up any space so each time an atom is split, we still have all the
>> space for those instructions.
>>
>
> I'm not sure how relevant this is to you/this issue, but one common idiom
> for shrinking vectors capacity is to use copy-and-swap:
>
> std::vector<T> v1 = v;
> v.swap(v1);
>
> v1 will generally be initialized with a practical capacity for the current
> size of 'v', ignoring v's currently bloated capacity, then swap will just
> trivially swap the buffer pointer/size/capacity between the two vectors, v1
> dies along with its excess capacity.
>
> This would save the extra couple of pointers per element you'll be paying
> to std::list. Though I don't know if there's a logical point in the program
> to do such shrinking, nor whether the other savings you describe from using
> list dominate the issue anyway.
I thought about doing something like this a little bit. I think the list is a win from the splitting during the construction, but once a basic block is complete, switching to a vector would be a nice savings. The problem is I don't know if that could be done prior to constructing the entire module. For something that's nice and well-formed, you could probably do it once you had completed a function.
--
Stephen Checkoway
More information about the llvm-commits
mailing list