[PATCH] D45571: [ELF] - Speedup MergeInputSection::splitStrings
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 13 03:45:46 PDT 2018
grimar added a comment.
In https://reviews.llvm.org/D45571#1066162, @espindola wrote:
> One interesting thing about the current setup is that we first read the bytes in the string looking for the 0 that terminates the string. We then read them again to hash them. At least with a simple hash like djb (what is implemented in hashGnu) it should not be too hard to read each byte once. Would you mind giving that a try?
No much difference for me:
Function Name Total CPU(%) Total CPU (ms)
* After the change:
- lld.exe (PID: 15032) 100.00 4166
+ lld::elf::MergeInputSection::splitIntoPieces 22.40 933
* Default (xxHash64):
- lld.exe 100.00% 4254
+ lld::elf::MergeInputSection::splitStrings 21.86% 930
My test code was:
static size_t findNull(StringRef S, size_t EntSize, uint32_t& H) {
uint32_t Hash = 5381;
// Optimize the common case.
if (EntSize == 1) {
const char *Data = S.data();
while (uint8_t C = *Data++)
Hash = (Hash << 5) + Hash + C;
H = Hash;
return Data - S.data();
}
llvm_unreachable("scylla?");
for (unsigned I = 0, N = S.size(); I != N; I += EntSize) {
const char *B = S.begin() + I;
if (std::all_of(B, B + EntSize, [](char C) { return C == 0; }))
return I;
}
}
// Split SHF_STRINGS section. Such section is a sequence of
// null-terminated strings.
void MergeInputSection::splitStrings(ArrayRef<uint8_t> Data, size_t EntSize) {
size_t Off = 0;
bool IsAlloc = Flags & SHF_ALLOC;
StringRef S = toStringRef(Data);
while (!S.empty()) {
uint32_t Hash;
size_t Size = findNull(S, EntSize, Hash);
Pieces.emplace_back(Off, Hash, !IsAlloc);
S = S.substr(Size);
Off += Size;
}
}
https://reviews.llvm.org/D45571
More information about the llvm-commits
mailing list