This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Optimize scudo test string allocation
ClosedPublic

Authored by ddcc on Oct 3 2022, 5:12 PM.

Details

Summary

When the underlying vector becomes full, it resizes, remaps, and then copies over the old data. To avoid thes excess allocations, allow reservation from the backing vector.

Diff Detail

Event Timeline

ddcc created this revision.Oct 3 2022, 5:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 5:12 PM
ddcc requested review of this revision.Oct 3 2022, 5:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 5:12 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka added inline comments.Nov 28 2022, 3:14 PM
compiler-rt/lib/scudo/standalone/string_utils.h
22

I don't like inconsistency with std:: or even Vector<> here
the Size argument is expected to be the new size of the container, not reserved size.

It the optimization is important, I would prefer something like:
explicit ScopedString() = default;
uptr length() { return Max(String.size(), 1) - 1; }
const char *data() { return String.size() ? String.data() : ""; }
ddcc added inline comments.Dec 1 2022, 8:19 PM
compiler-rt/lib/scudo/standalone/string_utils.h
22

How about just exposing the reserve method of the underlying container then? Where the reserved size is always incremented by one to account for the terminator.

vitalybuka added inline comments.Dec 6 2022, 11:15 AM
compiler-rt/lib/scudo/standalone/string_utils.h
22

lgtm

vitalybuka requested changes to this revision.Dec 6 2022, 11:15 AM
This revision now requires changes to proceed.Dec 6 2022, 11:15 AM
ddcc updated this revision to Diff 481801.Dec 9 2022, 5:23 PM

Call new reserve() method

vitalybuka accepted this revision.Dec 12 2022, 12:01 PM

Please update descriptions

This revision is now accepted and ready to land.Dec 12 2022, 12:01 PM
vitalybuka added inline comments.Dec 12 2022, 12:02 PM
compiler-rt/lib/scudo/standalone/string_utils.h
31
This revision was automatically updated to reflect the committed changes.
ddcc edited the summary of this revision. (Show Details)Dec 12 2022, 4:14 PM