llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

`llvm-objcopy --keep-symbols` is slower than GNU equivalent

Open llvmbot opened this issue 5 years ago • 4 comments

Bugzilla Link 50404
Resolution FIXED
Resolved on Sep 25, 2021 17:19
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @alexshap,@justincady,@MaskRay,@jh7370,@rupprecht

Extended Description

While investigating an issue with android build performance, I found that llvm-objcopy performance is far from parity with GNU objcopy for the "--keep-symbols" case, when the keep symbols list is very large.

I can see that llvm objcopy creates a list of NameOrPattern-s to represent the keep symbol list, but it looks like it exhaustively compares each symbol in the keep list against each symbol in the input file. Not sure what GNU objcopy does but merging the non-pattern symbol names into a sorted list would make searching much faster.

Below is a script to reproduce the problem and its output. The test case below demonstrates a significant performance difference. The android build failure case reported had a shared obj with ~700k symbols and the keep list was ~300k symbols and it took ~8 minutes to execute.


Here's the output I get when I run it on ToT-within-last-week-or-so:

$ PATH=$PWD/bin:$PATH ../../tmp/qt66370/32/objcopy_perf.sh
creating init file
creating obj file
creating shared obj file
ld.lld: warning: lld uses blx instruction, no object with architecture supporting feature detected
performing llvm objcopy
12.34user 0.00system 0:12.35elapsed 99%CPU (0avgtext+0avgdata 20228maxresident)k
0inputs+2288outputs (0major+3815minor)pagefaults 0swaps
performing GNU objcopy
0.03user 0.00system 0:00.04elapsed 97%CPU (0avgtext+0avgdata 20396maxresident)k
0inputs+2288outputs (0major+5895minor)pagefaults 0swaps

llvmbot avatar May 19 '21 15:05 llvmbot

This should be marked as fixed by 0144e625b9672d27b25196346134a7ac40e00e29, correct?

justincady avatar Aug 20 '21 18:08 justincady

I tested https://reviews.llvm.org/D105218 manually and confirmed it addressed the issue.

I had created a local patch that is extremely similar (I just used std::set instead of DenseSet, which I was unaware of). The concept of separating patterns from non-patterns seems to me to be the right approach.

Re-assigning the bug. I think the patch looks good and based on my testing fixes this bug. Thank you!

justincady avatar Jul 12 '21 14:07 justincady

GNU objcopy may be similarly slow if --wildcard is specified.

Sent https://reviews.llvm.org/D105218 to optimize for the non-wildcard-non-regex case.

MaskRay avatar Jun 30 '21 18:06 MaskRay

assigned to @MaskRay

llvmbot avatar May 19 '21 15:05 llvmbot