readAddressArea() implementation in part of searching inputsection
that range belongs to is ineffective. Implementation is O(N*M) where
N is number of input sections and M is number of ranges. Since
each input section may have own range, complexity can be quadratic.
Patch reimplements it using binary search.
For benchmark I used debug LLC binary built with -gsplit-dwarf and -ggnu-pubnames
Numbers are (20 runs for each):
- Original LLD without --gdb-index link time is 1,644984654 seconds ( +- 0,28% )
- LLD without patch + --gdb-index link time is 6,200055217 seconds ( +- 0,15% )
- LLD with this patch + --gdb-index link time is 4,305998886 seconds ( +- 0,16% )
Time spent for building gdbindex changes from (6.2 - 1.644 == 4.556) to (4.305 - 1.644 == 2.664).
That is 2.664/4.556 = 0.584 or about 42% speedup.
I also tried different solution without use of additional vector, demo is available: D32851, but this
patch is faster and looks cleaner.
This is often done nested like this, if you like