[PATCH] Change MCTextAtom to use std::list instead of std::vector

Stephen Checkoway s at pahtak.org
Tue Oct 15 11:45:35 PDT 2013


For what it's worth, after this change any my previous one, I get a bit of a speedup:

[secdev:~/build-master] s$ cat ~/ninja/ninja > /dev/null
[secdev:~/build-master] s$ time llvm-objdump -disassemble -symbolize -cfg ~/ninja/ninja > /dev/null

real    0m8.225s
user    0m4.368s
sys     0m3.796s
[secdev:~/build-master] s$ time bin/llvm-objdump -disassemble -symbolize -cfg ~/ninja/ninja > /dev/null

real    0m0.149s
user    0m0.124s
sys     0m0.020s

The speedup on ninja comes mostly from this patch as it no longer requires copying instructions and there aren't too many symbols (568) that would lead to a speedup from the first patch. I didn't actually compare the two directly, however.

S

On Oct 15, 2013, at 2:27 PM, 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.
> 
> Using a list also enables us to use std::list::splice() to split the instructions in constant time. There is still a linear scan to find the split point.
> 
> Maybe something could be done using smarter data structures or smarter choices of the order atoms are split, but I haven't gone down that route.
> 
> One consequence of switching to a list is that the MCTextAtom::at() function becomes inefficient since you would need to perform the linear scan. However, this is only used in two locations: MCModuleYAML and llvm-objdump. In both cases, the code was iterating over every instruction so the patch changes the loops to use iterators and MCTextAtom::at() is removed.
> 
> The patch could be split into two parts, one that changes from vector to list and fixes the two at() uses, and one that replaces the copy() + erase() with splice().
> 
> I still run out of memory trying to run it on my chromium with debug symbols but as Ahmed pointed out, there is probably room for improvement still. (A singly linked list would save some but C++98 doesn't appear to have one and there are probably better optimizations.)
> 
> -- 
> Stephen Checkoway
> 
> <MCTextAtom-use-list.diff>
> 
> 
> 

-- 
Stephen Checkoway









More information about the llvm-commits mailing list