Closed alexcrichton closed 6 years ago
Should be fixed in rL340428
This is a known issue. There was an old patch out the remove the N*M alotithm that is currently in there: https://reviews.llvm.org/D42176
I was planning on making a fix to the format to avoid this issue but I didn't get around it it yet. I'll see if I can land that patch in the interim.
Here is a gprof result. It shows that copyRelocations is extremely slow.
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
97.79 4.87 4.87 53361 0.00 0.00 lld::wasm::InputChunk::copyRelocations(llvm::object::WasmSection const&)
0.60 4.90 0.03 201290 0.00 0.00 bool llvm::DenseMapBase<llvm::DenseMap<llvm::CachedHashStringRef, lld::wasm::Symbol, llvm::DenseMapInfo
Essentially, when you are handling relocations in lld, you should be very careful not to waste time on each relocation, because there may be tens of millions of relocations, and literally every microsecond counts. Sam, do you have time to look at this?
Extended Description
When working with some wasm tools earlier today I realized that for one of our compilations in rust-lang/rust it takes LLD around 4 seconds to finish. I was quite surprised at this runtime because typically our linker invocations are quite speedy (under 1s most of the time, even non-incremental).
A gist 1 contains a tarball with a reproduction script and all the necessary files and there's also a direct link 2 to the tarball itself.
I do realize though that this is quite a large test case, there's ~100MB of input files which is generating ~20MB of an output. I suspect though that there may be some low hanging fruit to clear out though to improve link time here!