This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Specialize std::swap() for SetVector
ClosedPublic

Authored by nikic on Jun 19 2020, 12:46 PM.

Details

Summary

This is intended to address a compile-time regression from rG1eddce4177cfddc86d4696b758904443b0b4f193. A SmallPtrSet was replaced with a SetVector there, which had an unexpected large compile-time impact. It turns out that this structure is getting swapped a lot, and previously this used an optimized std::swap specialization for SmallPtrSet. Now it ends up using the default, triple-move based implementation, which is much more expensive.

This patch addresses the issue by specializing std::swap() for SetVector. I'll provide more specific compile-time numbers once I have them.

Diff Detail

Event Timeline

nikic created this revision.Jun 19 2020, 12:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2020, 12:46 PM

Interesting patch! I'm definitely interested in seeing the numbers. Though note this patch was made as a followup, which seems to have gotten about 1/2 of the original regression back: https://github.com/llvm/llvm-project/commit/837ca4796065ccd0ac0d20860341ac06a9645009

This makes any change to SmallSetVector no longer have an impact on this example.

nikic marked an inline comment as done.Jun 19 2020, 3:10 PM
llvm/include/llvm/ADT/SetVector.h
268

Something that I'm really stumped about: I initially used std::swap() here instead of the swap() member functions. However, for some reason that ends up picking up an optimized swap implementation for vector_, but not for set_ (which is the more important one really).

ychen added a subscriber: ychen.Jun 19 2020, 9:37 PM
erichkeane accepted this revision.Jul 9 2020, 11:58 AM

Please fix the clang-format concerns, otherwise LGTM.

This revision is now accepted and ready to land.Jul 9 2020, 11:58 AM
This revision was automatically updated to reflect the committed changes.