Commit 9b0b3e86 authored by Nicolas Pena's avatar Nicolas Pena Committed by Commit Bot

Add experimental performance.shouldYield()

Bug: 836310
Change-Id: Ib2d8796129e34c22c922e21b492e474130ea4420
Reviewed-on: https://chromium-review.googlesource.com/1057434
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562029}
parent b30707bf
......@@ -58,6 +58,7 @@ PASS window.cached_navigator_usb.ondisconnect is null
PASS window.cached_navigator_xr.ondevicechange is null
PASS window.cached_performance.oneventtimingbufferfull is null
PASS window.cached_performance.onresourcetimingbufferfull is null
PASS window.cached_performance.shouldYield is false
PASS window.cached_performance_navigation.redirectCount is 0
PASS window.cached_performance_navigation.type is 0
PASS window.cached_performance_timing.connectEnd is 0
......
......@@ -58,6 +58,7 @@ PASS window.cached_navigator_usb.ondisconnect is null
PASS window.cached_navigator_xr.ondevicechange is null
PASS window.cached_performance.oneventtimingbufferfull is null
PASS window.cached_performance.onresourcetimingbufferfull is null
PASS window.cached_performance.shouldYield is false
PASS window.cached_performance_navigation.redirectCount is 0
PASS window.cached_performance_navigation.type is 0
PASS window.cached_performance_timing.connectEnd is 0
......
......@@ -58,6 +58,7 @@ PASS window.cached_navigator_usb.ondisconnect is null
PASS window.cached_navigator_xr.ondevicechange is null
PASS window.cached_performance.oneventtimingbufferfull is null
PASS window.cached_performance.onresourcetimingbufferfull is null
PASS window.cached_performance.shouldYield is false
PASS window.cached_performance_navigation.redirectCount is 0
PASS window.cached_performance_navigation.type is 0
PASS window.cached_performance_timing.connectEnd is 0
......
......@@ -180,6 +180,7 @@ PASS oldChildWindow.performance.navigation.redirectCount is newChildWindow.perfo
PASS oldChildWindow.performance.navigation.type is newChildWindow.performance.navigation.type
PASS oldChildWindow.performance.oneventtimingbufferfull is newChildWindow.performance.oneventtimingbufferfull
PASS oldChildWindow.performance.onresourcetimingbufferfull is newChildWindow.performance.onresourcetimingbufferfull
PASS oldChildWindow.performance.shouldYield is newChildWindow.performance.shouldYield
PASS oldChildWindow.performance.timing.connectEnd is newChildWindow.performance.timing.connectEnd
PASS oldChildWindow.performance.timing.connectStart is newChildWindow.performance.timing.connectStart
PASS oldChildWindow.performance.timing.domComplete is newChildWindow.performance.timing.domComplete
......
......@@ -30,6 +30,7 @@ window.performance.onresourcetimingbufferfull [null]
window.performance.removeEventListener [function]
window.performance.setEventTimingBufferMaxSize [function]
window.performance.setResourceTimingBufferSize [function]
window.performance.shouldYield [boolean]
window.performance.timeOrigin [number]
window.performance.timing [object PerformanceTiming]
window.performance.timing.connectEnd [number]
......
......@@ -5032,6 +5032,7 @@ interface Performance : EventTarget
getter navigation
getter oneventtimingbufferfull
getter onresourcetimingbufferfull
getter shouldYield
getter timeOrigin
getter timing
method clearEventTimings
......
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>ShouldYield: clicks should make shouldYield return true.
</title>
<div>
Click the button and expect two green lines of text.
This test should be run under --enable-blink-features=ExperimentalShouldYield.
</div>
</head>
<button onclick="runTest()">Click me</button>
<p id="shortTaskResult"></p>
<p id="longTaskResult"></p>
<script>
// |expected| is the expected value from performance.shouldYield.
function createResult(expected) {
const result = document.createElement('div');
const shouldYield = performance.shouldYield;
if (shouldYield == expected) {
result.innerHTML = 'PASSED: performance.shouldYield was ' + shouldYield;
result.style = 'color:green';
}
else {
result.innerHTML = 'FAILED: performance.shouldYield was ' + shouldYield;
result.style = 'color:red';
}
return result;
}
function shortTaskCheck() {
document.getElementById("shortTaskResult").appendChild(createResult(false));
}
let hasPrinted = false;
function runTest() {
if (hasPrinted)
return;
// Be busy until shouldYield becomes true.
while ( !performance.shouldYield ) {}
document.getElementById('longTaskResult').appendChild(createResult(true));
hasPrinted = true;
setTimeout(shortTaskCheck, 0);
}
</script>
</html>
\ No newline at end of file
......@@ -120,6 +120,10 @@ MemoryInfo* Performance::memory() const {
return nullptr;
}
bool Performance::shouldYield() const {
return false;
}
DOMHighResTimeStamp Performance::timeOrigin() const {
DCHECK(!time_origin_.is_null());
return GetUnixAtZeroMonotonic() +
......
......@@ -85,6 +85,7 @@ class CORE_EXPORT Performance : public EventTargetWithInlineData {
virtual PerformanceTiming* timing() const;
virtual PerformanceNavigation* navigation() const;
virtual MemoryInfo* memory() const;
virtual bool shouldYield() const;
virtual void UpdateLongTaskInstrumentation() {}
......
......@@ -80,5 +80,8 @@ interface Performance : EventTarget {
// https://groups.google.com/a/chromium.org/d/msg/blink-dev/g5YRCGpC9vs/b4OJz71NmPwJ
[Exposed=Window, Measure] readonly attribute MemoryInfo memory;
// TODO(npm): This is an experimental attribute with no current plan to standardize. Remove once experiment has concluded. Only exposed to Window because we do not consider worker threads to contain high priority work.
[Exposed=Window, RuntimeEnabled=ExperimentalShouldYield] readonly attribute boolean shouldYield;
serializer = {attribute};
};
......@@ -31,6 +31,7 @@
#include "third_party/blink/renderer/core/timing/window_performance.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h"
......@@ -46,6 +47,7 @@
#include "third_party/blink/renderer/core/timing/performance_timing.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_timing_info.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
static const double kLongTaskObserverThreshold = 0.05;
......@@ -139,6 +141,13 @@ MemoryInfo* WindowPerformance::memory() const {
return MemoryInfo::Create();
}
bool WindowPerformance::shouldYield() const {
return Platform::Current()
->CurrentThread()
->Scheduler()
->ShouldYieldForHighPriorityWork();
}
PerformanceNavigationTiming*
WindowPerformance::CreateNavigationTimingInstance() {
if (!RuntimeEnabledFeatures::PerformanceNavigationTiming2Enabled())
......
......@@ -61,6 +61,8 @@ class CORE_EXPORT WindowPerformance final : public Performance,
MemoryInfo* memory() const override;
bool shouldYield() const override;
void UpdateLongTaskInstrumentation() override;
bool ObservingEventTimingEntries();
......
......@@ -452,6 +452,14 @@
name: "ExperimentalProductivityFeatures",
status: "experimental"
},
{
// Enables the attribute performance.shouldYield in windows. This
// attribute indicates that the frame should pause its current task so
// that the browser can perform some high priority work. See
// https://crbug.com/836310.
name: "ExperimentalShouldYield",
status: "experimental"
},
{
name: "ExperimentalV8Extras",
status: "experimental",
......
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