Commit 65320494 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup, third_party/blink/renderer/ edition.

* Shorten code
* Trivial naming/comment fixes
* Use const more
* Inline temps
* Event::marking_time_in_bytes_per_second() is unused (and actually
  mis-named); remove
* Use TimeDelta::InMicrosecondsF() to get a double

Bug: none
Change-Id: I324c6d82e04514e2a9105df05b5942eb2cfd9efb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359006
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798516}
parent a2deb4db
......@@ -1992,15 +1992,13 @@ base::Optional<AnimationTimeDelta> Animation::TimeToEffectChange() {
playback_rate_);
}
AnimationTimeDelta result =
playback_rate_ > 0
? content_->TimeToForwardsEffectChange() / playback_rate_
: content_->TimeToReverseEffectChange() / -playback_rate_;
return !HasActiveAnimationsOnCompositor() &&
content_->GetPhase() == Timing::kPhaseActive
? AnimationTimeDelta()
: result;
if (!HasActiveAnimationsOnCompositor() &&
(content_->GetPhase() == Timing::kPhaseActive))
return AnimationTimeDelta();
return (playback_rate_ > 0)
? (content_->TimeToForwardsEffectChange() / playback_rate_)
: (content_->TimeToReverseEffectChange() / -playback_rate_);
}
void Animation::cancel() {
......
......@@ -76,8 +76,8 @@ class CORE_EXPORT AnimationTimeDelta {
AnimationTimeDelta operator*(T a) const {
return AnimationTimeDelta(delta_ * a);
}
template <typename V>
AnimationTimeDelta& operator*=(V a) {
template <typename T>
AnimationTimeDelta& operator*=(T a) {
return *this = (*this * a);
}
template <typename T>
......
......@@ -174,8 +174,7 @@ static inline base::Optional<double> CalculateOverallProgress(
// through the current iteration that ignores transformations to the time
// introduced by the playback direction or timing functions applied to the
// effect.
// https://drafts.csswg.org/web-animations/#calculating-the-simple-iteration
// -progress
// https://drafts.csswg.org/web-animations/#calculating-the-simple-iteration-progress
static inline base::Optional<double> CalculateSimpleIterationProgress(
Timing::Phase phase,
base::Optional<double> overall_progress,
......
......@@ -62,7 +62,8 @@ void LayoutProgress::UpdateFromElement() {
double LayoutProgress::AnimationProgress() const {
if (!animating_)
return 0;
base::TimeDelta elapsed = base::TimeTicks::Now() - animation_start_time_;
const base::TimeDelta elapsed =
base::TimeTicks::Now() - animation_start_time_;
return (elapsed % animation_duration_) / animation_duration_;
}
......
......@@ -223,11 +223,10 @@ double VideoFrameCallbackRequesterImpl::GetCoarseClampedTimeInSeconds(
// stricter.
static_assert(kCoarseResolution >= base::TimeDelta::FromSecondsD(
TimeClamper::kResolutionSeconds),
"kCoarseResolutionInSeconds should be at least "
"as coarse as other clock resolutions");
double clamped_time = time.FloorToMultiple(kCoarseResolution).InSecondsF();
"kCoarseResolution should be at least as coarse as other clock "
"resolutions");
return clamped_time;
return time.FloorToMultiple(kCoarseResolution).InSecondsF();
}
int VideoFrameCallbackRequesterImpl::requestVideoFrameCallback(
......
......@@ -153,8 +153,8 @@ class VfcRequesterParameterVerifierCallback
EXPECT_NE(processing_time.InSecondsF(), metadata->processingDuration());
}
double last_now() { return now_; }
bool was_invoked() { return was_invoked_; }
double last_now() const { return now_; }
bool was_invoked() const { return was_invoked_; }
private:
void VerifyTicksClamping(base::TimeTicks reference,
......@@ -167,11 +167,10 @@ class VfcRequesterParameterVerifierCallback
}
double TicksToClampedMillisecondsF(base::TimeTicks ticks) {
constexpr double kSecondsToMillis = 1000.0;
return Performance::ClampTimeResolution(
timing_.MonotonicTimeToZeroBasedDocumentTime(ticks)
.InSecondsF()) *
kSecondsToMillis;
base::Time::kMillisecondsPerSecond;
}
double TicksToMillisecondsF(base::TimeTicks ticks) {
......@@ -180,12 +179,8 @@ class VfcRequesterParameterVerifierCallback
}
static double ClampElapsedProcessingTime(base::TimeDelta time) {
constexpr auto kProcessingTimeResolution =
base::TimeDelta::FromMicroseconds(100);
double clamped_time =
time.FloorToMultiple(kProcessingTimeResolution).InSecondsF();
return clamped_time;
return time.FloorToMultiple(base::TimeDelta::FromMicroseconds(100))
.InSecondsF();
}
double now_;
......@@ -344,7 +339,7 @@ TEST_F(VideoFrameCallbackRequesterImplTest, VerifyParameters) {
EXPECT_CALL(*media_player(), GetVideoFramePresentationMetadata())
.WillOnce(Return(ByMove(MetadataHelper::CopyDefaultMedatada())));
double now_ms =
const double now_ms =
timing.MonotonicTimeToZeroBasedDocumentTime(base::TimeTicks::Now())
.InMillisecondsF();
......
......@@ -200,12 +200,6 @@ base::TimeDelta ThreadHeapStatsCollector::Event::marking_time() const {
return foreground_marking_time() + background_marking_time();
}
double ThreadHeapStatsCollector::Event::marking_time_in_bytes_per_second()
const {
return marked_bytes ? marking_time().InMillisecondsF() / 1000 / marked_bytes
: 0.0;
}
base::TimeDelta ThreadHeapStatsCollector::Event::gc_cycle_time() const {
// Note that scopes added here also have to have a proper BlinkGCInV8Scope
// scope if they are nested in a V8 scope.
......
......@@ -265,9 +265,6 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
// Overall time spent sweeping the heap.
base::TimeDelta sweeping_time() const;
// Marking speed in bytes/s.
double marking_time_in_bytes_per_second() const;
// Marked bytes collected during sweeping.
size_t unique_id = -1;
size_t marked_bytes = 0;
......
......@@ -4,6 +4,8 @@
#include "third_party/blink/renderer/platform/heap/marking_scheduling_oracle.h"
#include "base/numerics/ranges.h"
namespace blink {
constexpr double MarkingSchedulingOracle::kEstimatedMarkingTimeMs;
......@@ -51,10 +53,8 @@ double MarkingSchedulingOracle::GetElapsedTimeInMs(base::TimeTicks start_time) {
base::TimeDelta MarkingSchedulingOracle::GetMinimumStepDuration() {
DCHECK_LT(0u, incrementally_marked_bytes_);
DCHECK(!incremental_marking_time_so_far_.is_zero());
base::TimeDelta minimum_duration = incremental_marking_time_so_far_ *
kMinimumMarkedBytesInStep /
incrementally_marked_bytes_;
return minimum_duration;
return incremental_marking_time_so_far_ * kMinimumMarkedBytesInStep /
incrementally_marked_bytes_;
}
base::TimeDelta MarkingSchedulingOracle::GetNextIncrementalStepDurationForTask(
......@@ -84,14 +84,12 @@ base::TimeDelta MarkingSchedulingOracle::GetNextIncrementalStepDurationForTask(
// up" by marking (|expected_marked_bytes| - |actual_marked_bytes|).
// Assuming constant marking speed, duration of the next incremental step
// should be as follows:
double marking_time_to_catch_up_in_ms =
(expected_marked_bytes - actual_marked_bytes) *
incremental_marking_time_so_far_.InMillisecondsF() /
const base::TimeDelta marking_time_to_catch_up =
incremental_marking_time_so_far_ *
(expected_marked_bytes - actual_marked_bytes) /
incrementally_marked_bytes_;
return std::min(
kMaximumIncrementalMarkingStepDuration,
std::max(minimum_duration, base::TimeDelta::FromMillisecondsD(
marking_time_to_catch_up_in_ms)));
return base::ClampToRange(marking_time_to_catch_up, minimum_duration,
kMaximumIncrementalMarkingStepDuration);
}
} // namespace blink
......@@ -364,20 +364,6 @@ TEST(ThreadHeapStatsCollectorTest, EventAtomicPause) {
stats_collector.previous().atomic_pause_time());
}
TEST(ThreadHeapStatsCollectorTest, EventMarkingTimePerByteInS) {
ThreadHeapStatsCollector stats_collector;
stats_collector.NotifyMarkingStarted(BlinkGC::CollectionType::kMajor,
BlinkGC::GCReason::kForcedGCForTesting,
true /* is_forced_gc */);
stats_collector.IncreaseScopeTime(
ThreadHeapStatsCollector::kAtomicPauseMarkTransitiveClosure,
base::TimeDelta::FromSeconds(1));
stats_collector.NotifyMarkingCompleted(1000);
stats_collector.NotifySweepingCompleted();
EXPECT_DOUBLE_EQ(
.001, stats_collector.previous().marking_time_in_bytes_per_second());
}
TEST(ThreadHeapStatsCollectorTest, EventSweepingTime) {
ThreadHeapStatsCollector stats_collector;
stats_collector.NotifyMarkingStarted(BlinkGC::CollectionType::kMajor,
......
......@@ -77,12 +77,10 @@ TEST_F(WriteBarrierPerfTest, MemberWritePerformance) {
// Reporting.
auto reporter = SetUpReporter("member_write_performance");
reporter.AddResult(
kMetricWritesDuringGcRunsPerS,
static_cast<double>(kNumElements) / during_gc_duration.InSecondsF());
reporter.AddResult(
kMetricWritesOutsideGcRunsPerS,
static_cast<double>(kNumElements) / outside_gc_duration.InSecondsF());
reporter.AddResult(kMetricWritesDuringGcRunsPerS,
kNumElements / during_gc_duration.InSecondsF());
reporter.AddResult(kMetricWritesOutsideGcRunsPerS,
kNumElements / outside_gc_duration.InSecondsF());
reporter.AddResult(kMetricRelativeSpeedDifferenceUnitless,
during_gc_duration / outside_gc_duration);
}
......
......@@ -26,6 +26,7 @@
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include <memory>
#include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_quality_estimator_params.h"
#include "third_party/blink/public/common/client_hints/client_hints.h"
......@@ -430,23 +431,19 @@ double NetworkStateNotifier::GetRandomMultiplier(const String& host) const {
uint32_t NetworkStateNotifier::RoundRtt(
const String& host,
const base::Optional<base::TimeDelta>& rtt) const {
// Limit the size of the buckets and the maximum reported value to reduce
// fingerprinting.
static const auto kGranularity = base::TimeDelta::FromMilliseconds(50);
static const auto kMaxRtt = base::TimeDelta::FromSeconds(3);
if (!rtt.has_value()) {
// RTT is unavailable. So, return the fastest value.
return 0;
}
base::TimeDelta modified_rtt = rtt.value();
modified_rtt *= GetRandomMultiplier(host);
modified_rtt = std::min(modified_rtt, kMaxRtt);
DCHECK_LE(base::TimeDelta(), modified_rtt);
DCHECK_GE(kMaxRtt, modified_rtt);
// Limit the maximum reported value and the granularity to reduce
// fingerprinting.
constexpr auto kMaxRtt = base::TimeDelta::FromSeconds(3);
constexpr auto kGranularity = base::TimeDelta::FromMilliseconds(50);
const base::TimeDelta modified_rtt =
std::min(rtt.value() * GetRandomMultiplier(host), kMaxRtt);
DCHECK_GE(modified_rtt, base::TimeDelta());
return static_cast<uint32_t>(
modified_rtt.RoundToMultiple(kGranularity).InMilliseconds());
}
......
......@@ -57,7 +57,7 @@ TEST_F(TimerPerfTest, PostAndRunTimers) {
test::EnterRunLoop();
double posting_time = (post_end - post_start).InMicroseconds();
double posting_time = (post_end - post_start).InMicrosecondsF();
double posting_time_us_per_call =
posting_time / static_cast<double>(kNumIterations);
LOG(INFO) << "TimerBase::startOneShot cost (us/call) "
......@@ -99,13 +99,13 @@ TEST_F(TimerPerfTest, PostThenCancelTenThousandTimers) {
test::EnterRunLoop();
double posting_time = (post_end - post_start).InMicroseconds();
double posting_time = (post_end - post_start).InMicrosecondsF();
double posting_time_us_per_call =
posting_time / static_cast<double>(kNumIterations);
LOG(INFO) << "TimerBase::startOneShot cost (us/call) "
<< posting_time_us_per_call << " (total " << posting_time << " us)";
double cancel_time = (cancel_end - cancel_start).InMicroseconds();
double cancel_time = (cancel_end - cancel_start).InMicrosecondsF();
double cancel_time_us_per_call =
cancel_time / static_cast<double>(kNumIterations);
LOG(INFO) << "TimerBase::stop cost (us/call) " << cancel_time_us_per_call
......
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