Commit 3e9f8a4f authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[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/1049647Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53085}
parent 8c57a54b
......@@ -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;
......
......@@ -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_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment