This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profgen] Do not cache the frame location stack during computing inlined context size
ClosedPublic

Authored by wlei on Jun 29 2022, 2:56 PM.

Details

Summary

In computeInlinedContextSizeForRange, the offset of range is only used one time, there is no need to cache the frame location stack.
Measured on one internal service binary, this can save 2GB memory usage and reduce a small run time (avoid one hash search).

Diff Detail

Event Timeline

wlei created this revision.Jun 29 2022, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 2:56 PM
Herald added subscribers: hoy, wenlei. · View Herald Transcript
wlei requested review of this revision.Jun 29 2022, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 2:56 PM
wlei edited the summary of this revision. (Show Details)Jun 29 2022, 3:05 PM
wlei added reviewers: hoy, wenlei.
hoy added a comment.Jul 7 2022, 5:00 PM

Nice catch!

llvm/tools/llvm-profgen/ProfiledBinary.h
503

How about extend this function with a parameter for caching or not?

wlei added inline comments.Jul 11 2022, 9:30 AM
llvm/tools/llvm-profgen/ProfiledBinary.h
503

It seems the return types of the two functions should be different, the one without caching should return the value type instead of the reference as we don't store it to a map.

hoy added inline comments.Jul 11 2022, 11:15 AM
llvm/tools/llvm-profgen/ProfiledBinary.h
503

I see. Then it makes sense to leave them separate.

How about flip the names, i.e

getFrameLocationStackWithoutCaching -> getFrameLocationStack

getFrameLocationStack -> getCachedFrameLocation

Caching is expansive so we want users to be explicitly aware of it. Also perhaps in the future we want to use two containers for cached contexts, one for UseProbeDiscriminator==true and one for UseProbeDiscriminator==false.

wlei added inline comments.Jul 11 2022, 4:01 PM
llvm/tools/llvm-profgen/ProfiledBinary.h
503

Renamed, thanks for the suggestion!

wlei updated this revision to Diff 443782.Jul 11 2022, 4:01 PM

renaming according to reviewer's suggestion

hoy accepted this revision.Jul 11 2022, 4:36 PM
This revision is now accepted and ready to land.Jul 11 2022, 4:36 PM
hoy added inline comments.Jul 11 2022, 4:37 PM
llvm/tools/llvm-profgen/ProfiledBinary.h
509

nit: getCachedFrameLocation -> getCachedFrameLocationStack

Sorry for missing it previously.

wlei updated this revision to Diff 443793.Jul 11 2022, 5:30 PM

Updating D128859: [llvm-profgen] Do not cache the frame location stack during computing inlined context size

wenlei accepted this revision.Oct 25 2022, 4:21 PM

Good find, thanks for the memory improvement!

This revision was landed with ongoing or failed builds.Oct 25 2022, 9:11 PM
This revision was automatically updated to reflect the committed changes.