From badeb15e5da42fb88eba823b20243a6507d0f99c Mon Sep 17 00:00:00 2001 From: Slava Egorov Date: Mon, 24 Nov 2025 13:29:52 -0800 Subject: [PATCH] [vm] Do not interrupt mutator when SampleBlock is complete This code was added when samples streaming was implemented and should not be necessary. Let background thread drain samples instead. This significantly reduces the overhead of activating profiler when using NativeRuntime.streamTimelineTo from 2-3x to ~10% in AOT mode and around ~20-25% in JIT. TEST=ci Change-Id: I4c6026f832d6a952b24323632b4126df6a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464183 Reviewed-by: Ryan Macnak Commit-Queue: Slava Egorov --- runtime/vm/profiler.cc | 7 +------ runtime/vm/thread.cc | 7 ------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/runtime/vm/profiler.cc b/runtime/vm/profiler.cc index 826285eefd6..ba9684da803 100644 --- a/runtime/vm/profiler.cc +++ b/runtime/vm/profiler.cc @@ -909,12 +909,7 @@ Sample* SampleBlockBuffer::ReserveSampleImpl(Isolate* isolate, if (block != nullptr) { block->MarkCompleted(); if (!Isolate::IsSystemIsolate(isolate)) { - Thread* mutator = isolate->IGNORE_RACE(mutator_thread)(); - // The mutator thread might be NULL if we sample in the middle of - // Thread::Enter/ExitIsolate. - if ((mutator != nullptr) && isolate->TrySetHasCompletedBlocks()) { - mutator->ScheduleInterrupts(Thread::kVMInterrupt); - } + isolate->TrySetHasCompletedBlocks(); } } return next->ReserveSample(); diff --git a/runtime/vm/thread.cc b/runtime/vm/thread.cc index 50611597b40..dde8b3f9a16 100644 --- a/runtime/vm/thread.cc +++ b/runtime/vm/thread.cc @@ -857,13 +857,6 @@ ErrorPtr Thread::HandleInterrupts(uword interrupt_bits) { } heap()->CheckFinalizeMarking(this); -#if !defined(PRODUCT) - // TODO(dartbug.com/60508): Allow profiling of isolate-group-shared code. - if (isolate() != nullptr && isolate()->TakeHasCompletedBlocks()) { - Profiler::ProcessCompletedBlocks(isolate()); - } -#endif // !defined(PRODUCT) - #if !defined(PRODUCT) || defined(FORCE_INCLUDE_SAMPLING_HEAP_PROFILER) HeapProfileSampler& sampler = heap_sampler(); if (sampler.ShouldSetThreadSamplingInterval()) {