This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
v8: don't busy loop in cpu profiler thread #9439
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The change in v0.10 (issue #8789) to sleep instead of
busy looping in the profiler processing thread is not
effective in v0.12 due to alterations in V8 to the
main loop in the processing thread.
As part of this V8 change, the responsibility for taking
stack samples been added to this loop to allow for the
sampling interval to be configured via the API.
This resulted in removing the previously present call to
YieldCPU().
The purpose of this commit is to recreate a similar fix in
v0.12 to the one provided for v0.10 in issue #8789.
The call to YieldCPU is reintroduced to the loop in the case
where there is no work to perform. Since YieldCPU was previously
modified to nanosleep (rather than sched_yield) on posix platforms,
and that change has been carried forward to 0.12, this will result
in a sleep for a period rounding up to the scheduler's granularity
on posix.
In v0.12 this could delay samples by the sleep period which would
be accurate on the unpatched code (since the loop now manages the
time at which samples are taken).
Additional:
This change (like issue #8789) is a patch to deps/v8 rather than node itself.
My understanding is that this was accepted previously because the v8 version (3.14) used by node (in 0.10) was significantly backlevel that it would not be patched upstream. I assume this is the case with 0.12 as well (which uses V8 3.28).
I have raised a V8 issue to address the problem on the latest V8 level (https://code.google.com/p/v8/issues/detail?id=3967).