[cpu-profiler] Add a HandleScope to limit memory consumption.

The handles created for each SharedFunctionInfo within
SourcePosition::InliningStack live for the life of the profile,
reaching 5MiB+ on an example server application for Node.

This HandleScope limits their lifetime locally, given that the handles
do not escape.

This saves ~10% of peak memory.

Bug: v8:7719
Change-Id: I97ce0fd3658be89fdd9cb9c1369ea5bfae0ce579
Reviewed-on: https://chromium-review.googlesource.com/1049647
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Alexei Filippov <alph@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53085}
This commit is contained in:
Peter Marshall 2018-05-08 11:57:11 +02:00 committed by Commit Bot
parent 8c57a54b86
commit 3e9f8a4f63
2 changed files with 8 additions and 1 deletions

View File

@ -17,7 +17,8 @@ namespace internal {
ProfilerListener::ProfilerListener(Isolate* isolate,
CodeEventObserver* observer)
: observer_(observer),
: isolate_(isolate),
observer_(observer),
function_and_resource_names_(isolate->heap()->HashSeed()) {}
ProfilerListener::~ProfilerListener() = default;
@ -276,6 +277,11 @@ void ProfilerListener::RecordDeoptInlinedFrames(CodeEntry* entry,
int deopt_id = static_cast<int>(info->data());
DCHECK(last_position.IsKnown());
std::vector<CpuProfileDeoptFrame> inlined_frames;
// SourcePosition::InliningStack allocates a handle for the SFI of each
// frame. These don't escape this function, but quickly add up. This
// scope limits their lifetime.
HandleScope scope(isolate_);
for (SourcePositionInfo& pos_info : last_position.InliningStack(code)) {
if (pos_info.position.ScriptOffset() == kNoSourcePosition) continue;
if (!pos_info.function->script()->IsScript()) continue;

View File

@ -84,6 +84,7 @@ class ProfilerListener : public CodeEventListener {
observer_->CodeEventHandler(evt_rec);
}
Isolate* isolate_;
CodeEventObserver* observer_;
StringsStorage function_and_resource_names_;
std::deque<std::unique_ptr<CodeEntry>> code_entries_;