Using multiple context used to be a really big memory saving because we could free memory from each file while the linker proceeded with the the symbol resolution. We are getting lazier about reading data from the bitcode, so I was curious if this was still a good tradeoff.
One thing that is a bit annoying is that we still have to copy the symbol names. The problem is that the names are stored in the Module and get freed when we move the module bits during linking.
Long term I think the solution is to add a symbol table to the bitcode. That way IRObject file will not need to use a Module or a Context and we can drop it while still keeping a StringRef to the names.
This patch might still be an interesting medium term improvement.
When linking llvm-as without debug info this patch is a small speedup:
master: 29.861877513 seconds
patch: 29.814533787 seconds
With debug info the numbers are
master: 34.765181469 seconds
patch: 34.563351584 seconds
The peak memory usage when linking llvm-as with debug info was
master: 599.10MB
patch: 600.13MB
I'd move this to initLLVM and swap the order of initLLVM and readConfigs.