This is an archive of the discontinued LLVM Phabricator instance.

[ELF] --gdb-index: use const char *, uint32_t to replace CachedHashStringRef
AbandonedPublic

Authored by MaskRay on Nov 27 2018, 12:51 PM.

Details

Summary

This decreases the size of NameAttrEntry from 20 bytes to 16 bytes on 64-bit platforms.

Event Timeline

MaskRay created this revision.Nov 27 2018, 12:51 PM
ruiu added a comment.Nov 27 2018, 1:07 PM

I believe the memory savings of this patch is not free; it now has to scan the same string more than once to find a null terminator. Even though we want to reduce memory usage of lld for Google, in general, saving memory is not always the goal that we want to achieve. We need to get a right balance. To do that, can you tell me how much memory you can save with this patch, and how much is the performance penalty of this patch?

MaskRay added a comment.EditedNov 27 2018, 2:07 PM

I believe the memory savings of this patch is not free; it now has to scan the same string more than once to find a null terminator. Even though we want to reduce memory usage of lld for Google, in general, saving memory is not always the goal that we want to achieve. We need to get a right balance. To do that, can you tell me how much memory you can save with this patch, and how much is the performance penalty of this patch?

I think the memory saving may be negligible but interestingly my testing says it makes it faster when linking clang. My understanding is that the smaller size of NameAttrs improves caching a bit.

cmake -H. -BStaticDebug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXE_LINKER_FLAGS=-Wl,--gdb-index ...
rm bin/clang-8; ninja -C StaticDebug -v -n clang to extract the clang command line, append '-###' to get the ld.lld command line. bin/clang-8 is of 601,059,920 bytes

perf stat -r 20 /tmp/link-clang => run several times without and with the patch. Without the patch it is usually 4.8 seconds (4.884600870 seconds time elapsed) while with the patch, it is usually 4.7 seconds (4.743274463 seconds time elapsed).

Even though we want to reduce memory usage of lld for Google

Thanks for the reminder but please believe I weigh much the general-purpose usability a lot.

ruiu added a comment.Nov 27 2018, 2:59 PM

I tried this patch myself, but it is hard to say if this patch makes a difference. Probably the performance difference is negligible.

Do you know how many NameAttrEntry's are created for your test case? (I.e. how many bytes are saved?)

  • For clang, the total number of NameAttrs is 32496
  • For an internal larger executable, it is 193776

I think both memory/space changes are negligible (I made a mistake when giving the statistics "4.8 seconds (4.884600870 seconds time elapsed) while with the patch, it is usually 4.7": used a wrong ld.lld).

ruiu added a comment.Nov 27 2018, 3:53 PM

Thank you for measuring it. Given these numbers, I wouldn't land this change as StringRef is more straightforward.

MaskRay abandoned this revision.Nov 27 2018, 3:54 PM