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