This is an archive of the discontinued LLVM Phabricator instance.

SourceManager: Fix an SLocEntry memory regression introduced with FileEntryRef
ClosedPublic

Authored by dexonsmith on Oct 16 2020, 11:46 AM.

Details

Summary

4dc5573acc0d2e7c59d8bac2543eb25cb4b32984 added FileEntryRef in order to
help enable sharing of a FileManager between CompilerInstances.

It also added a StringRef with the filename on FileInfo. This
doubled sizeof(FileInfo), bloating sizeof(SLocEntry), of which we
have one for each (loaded and unloaded) file and macro expansion. This
causes a memory regression in modules builds.

Move the filename down into the ContentCache, which is a side data
structure for FileInfo that does not impact sizeof(SLocEntry). Once
FileEntryRef is used for ContentCache::OrigEntry this can go away.

Diff Detail

Event Timeline

dexonsmith created this revision.Oct 16 2020, 11:46 AM
JDevlieghere added inline comments.Oct 22 2020, 10:40 PM
clang/include/clang/Basic/SourceManager.h
315

Would it possibly make more sense to drop the const qualifier from the argument?

dexonsmith planned changes to this revision.Oct 23 2020, 9:45 AM
dexonsmith added inline comments.
clang/include/clang/Basic/SourceManager.h
315

Yes, that's probably better. I'll make a prep commit that changes getOrCreateContentCache() to return non-const and thread that through to here, and then this is just Con.Filename = Filename.

dexonsmith marked an inline comment as done.Oct 23 2020, 12:23 PM
arphaman accepted this revision.Oct 23 2020, 4:56 PM
This revision is now accepted and ready to land.Oct 23 2020, 4:56 PM

Thanks for the review! @JDevlieghere, let me know if the updated patch looks good to you too (also the prep commit).

JDevlieghere accepted this revision.Oct 23 2020, 8:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2020, 12:38 PM