Commit b94733f8 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Migrate SpeculationsPumpSession to use ElapsedTimer instead of doubles

First things first, SpeculationsPumpSession was storing a base::Time at creation
time to compute an elpased time later on. Using base::TimeTicks is probably
better here since we are not interested in dates but in timestamps.

Since the only purpose of that timestamp is to compute an elapsed time, using a
base::ElapsedTimer seems the perfect fit.

Bug: 979137
Change-Id: Ifbfec4dc9562d79cd0db7d1b158d4acb16c2f1f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1705918Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#678303}
parent ec44c42e
......@@ -37,13 +37,12 @@ namespace blink {
SpeculationsPumpSession::SpeculationsPumpSession(unsigned& nesting_level)
: NestingLevelIncrementer(nesting_level),
start_time_(CurrentTime()),
processed_element_tokens_(0) {}
SpeculationsPumpSession::~SpeculationsPumpSession() = default;
inline double SpeculationsPumpSession::ElapsedTime() const {
return CurrentTime() - start_time_;
inline base::TimeDelta SpeculationsPumpSession::ElapsedTime() const {
return start_time_.Elapsed();
}
void SpeculationsPumpSession::AddedElementTokens(size_t count) {
......@@ -103,7 +102,8 @@ inline bool HTMLParserScheduler::ShouldYield(
if (ThreadScheduler::Current()->ShouldYieldForHighPriorityWork())
return true;
const double kParserTimeLimit = 0.5;
const base::TimeDelta kParserTimeLimit =
base::TimeDelta::FromMilliseconds(500);
if (session.ElapsedTime() > kParserTimeLimit)
return true;
......
......@@ -29,6 +29,7 @@
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/single_thread_task_runner.h"
#include "base/timer/elapsed_timer.h"
#include "third_party/blink/renderer/core/html/parser/nesting_level_incrementer.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cancellable_task.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
......@@ -44,12 +45,12 @@ class SpeculationsPumpSession : public NestingLevelIncrementer {
SpeculationsPumpSession(unsigned& nesting_level);
~SpeculationsPumpSession();
double ElapsedTime() const;
base::TimeDelta ElapsedTime() const;
void AddedElementTokens(size_t count);
size_t ProcessedElementTokens() const { return processed_element_tokens_; }
private:
double start_time_;
base::ElapsedTimer start_time_;
size_t processed_element_tokens_;
};
......
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