This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Change std::vector to SmallVector
AcceptedPublic

Authored by nadav on Jul 14 2020, 10:47 PM.

Details

Summary

The size of VTList that is pushed into this container is usually 1, but often 6 or 7. Change the vector to SmallVector to eliminate frequent mallocs.
This happens hundreds of thousands of times in each tablegen execution during the LLVM/clang build.

Diff Detail

Event Timeline

nadav created this revision.Jul 14 2020, 10:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2020, 10:47 PM
nadav edited the summary of this revision. (Show Details)Jul 15 2020, 10:27 AM

Reserve space in a vector to reduce the number of mallocs. The size of VTList is usually 1, but often 6 or 7.

It seems to me that SmallVector fits the need better than std::vector here?

Also curious how did you discover this?

nadav updated this revision to Diff 278372.Jul 15 2020, 10:25 PM
nadav retitled this revision from [TableGen] Reserve space in a vector to reduce the number of mallocs. to [TableGen] Change std::vector to SmallVector.
nadav edited the summary of this revision. (Show Details)
wenlei accepted this revision.Jul 15 2020, 10:28 PM

LGTM. Thanks!

This revision is now accepted and ready to land.Jul 15 2020, 10:28 PM

@wenlei You are right. SmallVector is a better fit. I updated the patch.

This patch, and D83920. D83797, D83788 that I sent today were all discovered by an internal performance tool.