This is an archive of the discontinued LLVM Phabricator instance.

[Support] Don't initialize compressed buffer allocated by zlib::compress
ClosedPublic

Authored by MaskRay on Aug 2 2018, 9:51 PM.

Details

Reviewers
ruiu
dblaikie
Summary

Initialization (zeroing) makes makes every allocated page resident. The actual size of the compressed buffer is usually much smaller. Making every page resident is wasteful.

When linking a test binary with ~1.9GiB uncompressed debug info with LLD, this optimization decreases max RSS by ~1.5GiB.

Diff Detail

Event Timeline

MaskRay created this revision.Aug 2 2018, 9:51 PM

There are very few users of zlib::compress operating on SmallVectorImpl<char>. If the two overloads seem redundant, I can remove the SmallVectorImpl<char> overload in future revision.

grimar added a subscriber: grimar.Aug 2 2018, 10:47 PM
ruiu added a comment.Aug 3 2018, 10:39 AM

This is very interesting!

include/llvm/Support/Compression.h
36–38

I think you should replace this function entirely with the new one because this is LLVM-only function and you can update all callers.

MaskRay updated this revision to Diff 159051.Aug 3 2018, 10:59 AM

Remove zlib::compress on SmallVectorImpl and change all callers to use std::unique_ptr<uint8_t[]>

ruiu added a comment.Aug 3 2018, 11:07 AM

If you are using git-svn, can you combine this patch with your another patch for lld, so that we can review this API-changing patch as one patch?

ruiu added inline comments.Aug 3 2018, 11:09 AM
lib/Support/Compression.cpp
65

I think you should sync to the head. This line is already gone.

ruiu added a comment.Aug 3 2018, 11:44 AM

If you are using git, you can actually combine this patch work your another patch as a single patch.

If you are using git, you can actually combine this patch work your another patch as a single patch.

I use git but not mono-repo git..

git clone https://git.llvm.org/git/llvm.git
cd llvm/tools
git clone https://git.llvm.org/git/clang.git

I cannot combine this with changes in clang.

The change on clang's side is at https://reviews.llvm.org/D50267

SmallVector has a method set_size to change the size of the vector without initializing the elements; you don't need to switch to unique_ptr just for that.

MaskRay updated this revision to Diff 159067.Aug 3 2018, 12:28 PM

Use set_size

MaskRay marked an inline comment as done.Aug 3 2018, 12:29 PM
MaskRay retitled this revision from [Support] Add zlib::compress which operates on std::unique_ptr<uint8_t[]> to [Support] Don't initialize compressed buffer allocated by zlib::compress.
MaskRay edited the summary of this revision. (Show Details)
MaskRay edited the summary of this revision. (Show Details)Aug 3 2018, 12:30 PM
ruiu accepted this revision.Aug 3 2018, 12:34 PM

LGTM

This revision is now accepted and ready to land.Aug 3 2018, 12:34 PM
MaskRay closed this revision.Aug 3 2018, 12:42 PM

Committed in rL338913

This is not closed automatically because I amended the git commit and inserted

Differential Revision: https://reviews.llvm.org/50223  # but I missed a `D` here...