This is an archive of the discontinued LLVM Phabricator instance.

make ConstStringTable use DenseMap rather than std::map
ClosedPublic

Authored by llunak on Apr 2 2022, 8:24 AM.

Details

Summary

The ordering is not needed, and DenseMap is faster. I can measure time spent in the SaveToCache() calls reduced to ~40% during LLDB startup (and the total startup cost reduced to ~70%).

Diff Detail

Event Timeline

llunak created this revision.Apr 2 2022, 8:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2022, 8:24 AM
llunak requested review of this revision.Apr 2 2022, 8:24 AM

I feel like this came up in the past and there was a reason an unordered map couldn't work? Maybe I'm confusing this with something else. Added Pavel as he would certainly know.

Could we use a llvm::DenseMap here, as it's supposedly even faster than its STL counterpart?

(Adding myself as a reviewer too so this shows up in my review queue)

llunak updated this revision to Diff 419996.Apr 2 2022, 9:50 AM
llunak retitled this revision from make ConstStringTable use std::unordered_map rather than std::map to make ConstStringTable use DenseMap rather than std::map.
llunak edited the summary of this revision. (Show Details)

Could we use a llvm::DenseMap here, as it's supposedly even faster than its STL counterpart?

Yes, it is, I've updated the patch.

clayborg accepted this revision.Apr 2 2022, 1:41 PM
This revision is now accepted and ready to land.Apr 2 2022, 1:41 PM
labath accepted this revision.Apr 4 2022, 6:47 AM

I feel like this came up in the past and there was a reason an unordered map couldn't work? Maybe I'm confusing this with something else. Added Pavel as he would certainly know.

This is pretty new code, so I think you must be thinking of something else.

I don't see any reason why this would have to be a std::map. I think the code just hasn't been optimized yet.

JDevlieghere accepted this revision.Apr 4 2022, 8:54 AM

I feel like this came up in the past and there was a reason an unordered map couldn't work? Maybe I'm confusing this with something else. Added Pavel as he would certainly know.

This is pretty new code, so I think you must be thinking of something else.

I don't see any reason why this would have to be a std::map. I think the code just hasn't been optimized yet.

Cool, thanks for confirming. LGTM!