This is an archive of the discontinued LLVM Phabricator instance.

[lld][MachO] Sort symbols in parallel in -map
ClosedPublic

Authored by TH3CHARLie on Jun 15 2021, 6:51 PM.

Details

Reviewers
int3
gkm
thakis
Group Reviewers
Restricted Project
Commits
rG01cb9c5fc52b: [lld][MachO] Sort symbols in parallel in -map
Summary

source: https://bugs.llvm.org/show_bug.cgi?id=50689

When writing a map file, sort symbols in parallel using parallel_sort.
Use address name to break ties if two symbols have the same address.

Diff Detail

Event Timeline

TH3CHARLie created this revision.Jun 15 2021, 6:51 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
TH3CHARLie requested review of this revision.Jun 15 2021, 6:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2021, 6:51 PM

Is there a demonstrable speed-up?

thakis added a subscriber: thakis.Jun 15 2021, 7:07 PM

Seems fine, but can you change the patch description to say "When writing a map file, sort symbols in parallel" to make clear that this only affects map file writing?

TH3CHARLie retitled this revision from [lld][MachO] Sort symbols in parallel to [lld][MachO] Sort symbols in parallel in -map.Jun 15 2021, 7:18 PM
TH3CHARLie edited the summary of this revision. (Show Details)
TH3CHARLie edited the summary of this revision. (Show Details)

Seems fine, but can you change the patch description to say "When writing a map file, sort symbols in parallel" to make clear that this only affects map file writing?

resolved

Is there a demonstrable speed-up?

Trying to produce one, please stay tune...

int3 added a comment.Jun 15 2021, 10:01 PM

Trying to produce one

We often use this Chromium build snapshot as a benchmark: https://drive.google.com/file/d/1j6_f55jX1WYjwrDSmQYbr_X043mLG9L2/view?usp=sharing

Download and unpack it, then you can run the link command like so ld64.lld -map mapoutputfile @response.txt

You'll want to run it a number of times. This is the script that I usually use:

(base) lld/MachO: cat `which bench.sh`
#!/bin/bash
set -x
echo "warming up..." >&2
$@
for i in {1..20}
do
  /usr/bin/time -p $@ 2>&1 | grep "^real " | awk '{print $2}'
done

I typically use that script to generate two sets of measurements, one before and one after this diff is applied. Then I compare the results using https://github.com/codahale/ministat. The commit message in D103979 is an example of the result.

lld/MachO/MapFile.cpp
55–59

I think this can just be llvm::parallel_sort (and with the using namespace llvm above, we don't even need the llvm::). Stuff under detail namespaces shouldn't be used directly -- they're implementation details

TH3CHARLie added inline comments.Jun 15 2021, 11:07 PM
lld/MachO/MapFile.cpp
55–59

parallel_sort is not available in llvm namespace, parallelSort is. So maybe we should use parallelSort here?

int3 added inline comments.Jun 15 2021, 11:22 PM
lld/MachO/MapFile.cpp
55–59

ah yes. I was thinking of parallelSort

Use llvm::parallelSort

TH3CHARLie added a comment.EditedJun 16 2021, 12:16 AM

I reproduce a benchmark number following @int3 's guidance, though the numbers are not as promising as I expected:

cc @MaskRay

#../ministat/ministat -s -w 74 stable.txt parallel.txt
x stable.txt
+ parallel.txt
+--------------------------------------------------------------------------+
|                           +            +     +                           |
|                         + +   x x+     +     +  x x                      |
|+                  + xx ++ ++ xx x* ** ** x   +  x xx x                  x|
|                            |__________MA____________|                    |
|                     |__________A_M________|                              |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  20          6.53          6.88          6.65         6.661   0.083154897
+  20          6.39           6.7          6.62        6.6055    0.07444355
Difference at 95.0% confidence
        -0.0555 +/- 0.050512
        -0.833208% +/- 0.758325%
        (Student's t, pooled s = 0.0789195)
thakis accepted this revision.Jun 16 2021, 3:54 AM

Do you need someone to commit this for you, or do you have commit permissions.

(FWIW https://github.com/nico/hack/blob/master/bench.py is my "run multiple times" script :) )

This revision is now accepted and ready to land.Jun 16 2021, 3:54 AM

Do you need someone to commit this for you, or do you have commit permissions.

(FWIW https://github.com/nico/hack/blob/master/bench.py is my "run multiple times" script :) )

Thanks for the review and I have commit access

Should I wait for @int3 or I can commit now?

int3 accepted this revision.Jun 16 2021, 11:52 AM

lgtm, thanks!

lld/MachO/MapFile.cpp
55–59

since we have using namespace above

TH3CHARLie marked 2 inline comments as done.Jun 16 2021, 6:49 PM
This revision was landed with ongoing or failed builds.Jun 16 2021, 7:20 PM
This revision was automatically updated to reflect the committed changes.