This is an archive of the discontinued LLVM Phabricator instance.

Avoid dsymutil calls to getFileNameByIndex
ClosedPublic

Authored by pete on Jul 21 2016, 3:45 PM.

Details

Summary

Hi Fred

getFileNameByIndex calls sys::path::append and (transitively) malloc a large number of times.

The call site in getChildDeclContext already caches resolved paths for a given FileNum if we have the file name by its index.

This patch adds a hasFileNameByIndex method. getChildDeclContext can first call this method, and if it returns true it knows it can then lookup the resolved path cache for the given file index. If we hit that cache then we don't even have to call getFileNameByIndex.

Running dsymutil on the swift executable generated from the GitHub sources, before this change took 100s on my iMac. Afterwards took 80s. So a nice 20% speedup. I ran a few times on each configuration to make sure the numbers are quite stable. I also diffed the dSYM produced before and after this patch and they are binary identical.

Thanks,
Pete

Diff Detail

Repository
rL LLVM

Event Timeline

pete updated this revision to Diff 64980.Jul 21 2016, 3:45 PM
pete retitled this revision from to Avoid dsymutil calls to getFileNameByIndex.
pete updated this object.
pete added a reviewer: friss.
pete set the repository for this revision to rL LLVM.
pete added a subscriber: llvm-commits.
friss accepted this revision.Jul 21 2016, 6:24 PM
friss edited edge metadata.

This LGTM if you agree with my comments. Thanks for the nice speed boost!

include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
191–192

I know you modeled the name on the function below, but it reads strange to me. How about just

bool hasFileAtIndex(uint64_t FileIndex) const;

(ie also drop the Kind parameter, I don't think it makes sense to test it here.)

lib/DebugInfo/DWARF/DWARFDebugLine.cpp
630–633

I like

return FileIndex != 0 && FileIndex <= Prologue.FileNames.size() ;

better (if you drop the Kind like I said above)

641

Then this becomes:

if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
This revision is now accepted and ready to land.Jul 21 2016, 6:24 PM
pete closed this revision.Jul 21 2016, 6:49 PM

Thanks for the quick review Fred. Those comments make complete sense so have committed with those changes.

r276380

Cheers,
Pete