Commit 399a3aff authored by Steve Kobes's avatar Steve Kobes Committed by Commit Bot

Update terminology and trace event fields in LayoutShiftTracker.

The trace event now incorporates move distance into the score field,
reflecting CLS calculation, and score_with_move_distance is removed.

PerFrameTraceData now computes the granularity scale instead of having
it passed in.  This paves the way to defer reporting on pointerdown.

Also removed references to "jank" in variable names and comments.

Bug: 963474, 978027
Change-Id: I87d69aa628446c46ce25647914b5d9c0dbcc1fcd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1714992Reviewed-by: default avatarBryan McQuade <bmcquade@chromium.org>
Commit-Queue: Steve Kobes <skobes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680434}
parent 35d9a4f3
...@@ -50,7 +50,8 @@ static float GetMoveDistance(const FloatRect& old_rect, ...@@ -50,7 +50,8 @@ static float GetMoveDistance(const FloatRect& old_rect,
return std::max(fabs(location_delta.Width()), fabs(location_delta.Height())); return std::max(fabs(location_delta.Width()), fabs(location_delta.Height()));
} }
static float RegionGranularityScale(const IntRect& viewport) { float LayoutShiftTracker::RegionGranularityScale(
const IntRect& viewport) const {
if (RuntimeEnabledFeatures::JankTrackingSweepLineEnabled()) if (RuntimeEnabledFeatures::JankTrackingSweepLineEnabled())
return kSweepLineRegionGranularity; return kSweepLineRegionGranularity;
...@@ -121,7 +122,7 @@ LayoutShiftTracker::LayoutShiftTracker(LocalFrameView* frame_view) ...@@ -121,7 +122,7 @@ LayoutShiftTracker::LayoutShiftTracker(LocalFrameView* frame_view)
observed_input_or_scroll_(false), observed_input_or_scroll_(false),
most_recent_input_timestamp_initialized_(false) {} most_recent_input_timestamp_initialized_(false) {}
void LayoutShiftTracker::AccumulateJank( void LayoutShiftTracker::ObjectShifted(
const LayoutObject& source, const LayoutObject& source,
const PropertyTreeState& property_tree_state, const PropertyTreeState& property_tree_state,
FloatRect old_rect, FloatRect old_rect,
...@@ -144,7 +145,7 @@ void LayoutShiftTracker::AccumulateJank( ...@@ -144,7 +145,7 @@ void LayoutShiftTracker::AccumulateJank(
// Ignore layout objects that move (in the coordinate space of the paint // Ignore layout objects that move (in the coordinate space of the paint
// invalidation container) on scroll. // invalidation container) on scroll.
// TODO(skobes): Find a way to detect when these objects jank. // TODO(skobes): Find a way to detect when these objects shift.
if (source.IsFixedPositioned() || source.IsStickyPositioned()) if (source.IsFixedPositioned() || source.IsStickyPositioned())
return; return;
...@@ -232,8 +233,8 @@ void LayoutShiftTracker::NotifyObjectPrePaint( ...@@ -232,8 +233,8 @@ void LayoutShiftTracker::NotifyObjectPrePaint(
if (!IsActive()) if (!IsActive())
return; return;
AccumulateJank(object, property_tree_state, FloatRect(old_visual_rect), ObjectShifted(object, property_tree_state, FloatRect(old_visual_rect),
FloatRect(new_visual_rect)); FloatRect(new_visual_rect));
} }
void LayoutShiftTracker::NotifyCompositedLayerMoved( void LayoutShiftTracker::NotifyCompositedLayerMoved(
...@@ -247,8 +248,8 @@ void LayoutShiftTracker::NotifyCompositedLayerMoved( ...@@ -247,8 +248,8 @@ void LayoutShiftTracker::NotifyCompositedLayerMoved(
if (!layout_object.FirstFragment().HasLocalBorderBoxProperties()) if (!layout_object.FirstFragment().HasLocalBorderBoxProperties())
return; return;
AccumulateJank(layout_object, PropertyTreeStateFor(layout_object), ObjectShifted(layout_object, PropertyTreeStateFor(layout_object),
old_layer_rect, new_layer_rect); old_layer_rect, new_layer_rect);
} }
double LayoutShiftTracker::SubframeWeightingFactor() const { double LayoutShiftTracker::SubframeWeightingFactor() const {
...@@ -296,8 +297,8 @@ void LayoutShiftTracker::NotifyPrePaintFinished() { ...@@ -296,8 +297,8 @@ void LayoutShiftTracker::NotifyPrePaintFinished() {
double(scaled_viewport.Width()) * double(scaled_viewport.Height()); double(scaled_viewport.Width()) * double(scaled_viewport.Height());
uint64_t region_area = uint64_t region_area =
use_sweep_line ? region_experimental_.Area() : region_.Area(); use_sweep_line ? region_experimental_.Area() : region_.Area();
double jank_fraction = region_area / viewport_area; double impact_fraction = region_area / viewport_area;
DCHECK_GT(jank_fraction, 0); DCHECK_GT(impact_fraction, 0);
DCHECK_GT(frame_max_distance_, 0.0); DCHECK_GT(frame_max_distance_, 0.0);
double viewport_max_dimension = std::max(viewport.Width(), viewport.Height()); double viewport_max_dimension = std::max(viewport.Width(), viewport.Height());
...@@ -305,11 +306,10 @@ void LayoutShiftTracker::NotifyPrePaintFinished() { ...@@ -305,11 +306,10 @@ void LayoutShiftTracker::NotifyPrePaintFinished() {
(frame_max_distance_ < viewport_max_dimension) (frame_max_distance_ < viewport_max_dimension)
? double(frame_max_distance_) / viewport_max_dimension ? double(frame_max_distance_) / viewport_max_dimension
: 1.0; : 1.0;
double jank_fraction_with_move_distance = double score_delta = impact_fraction * move_distance_factor;
jank_fraction * move_distance_factor;
if (!HadRecentInput()) if (!HadRecentInput())
score_ += jank_fraction_with_move_distance; score_ += score_delta;
overall_max_distance_ = std::max(overall_max_distance_, frame_max_distance_); overall_max_distance_ = std::max(overall_max_distance_, frame_max_distance_);
...@@ -318,24 +318,21 @@ void LayoutShiftTracker::NotifyPrePaintFinished() { ...@@ -318,24 +318,21 @@ void LayoutShiftTracker::NotifyPrePaintFinished() {
if (!HadRecentInput() && ShouldLog(frame)) { if (!HadRecentInput() && ShouldLog(frame)) {
DVLOG(1) << "in " << (frame.IsMainFrame() ? "" : "subframe ") DVLOG(1) << "in " << (frame.IsMainFrame() ? "" : "subframe ")
<< frame.GetDocument()->Url().GetString() << ", viewport was " << frame.GetDocument()->Url().GetString() << ", viewport was "
<< (jank_fraction * 100) << "% janked with distance fraction " << (impact_fraction * 100) << "% impacted with distance fraction "
<< move_distance_factor << "; raising score to " << score_; << move_distance_factor << "; raising score to " << score_;
} }
#endif #endif
TRACE_EVENT_INSTANT2( TRACE_EVENT_INSTANT2("loading", "LayoutShift", TRACE_EVENT_SCOPE_THREAD,
"loading", "LayoutShift", TRACE_EVENT_SCOPE_THREAD, "data", "data", PerFrameTraceData(score_delta, HadRecentInput()),
PerFrameTraceData(jank_fraction, jank_fraction_with_move_distance, "frame", ToTraceValue(&frame));
granularity_scale, HadRecentInput()),
"frame", ToTraceValue(&frame));
if (!HadRecentInput()) { if (!HadRecentInput()) {
double weighted_jank_fraction_with_move_distance = double weighted_score_delta = score_delta * SubframeWeightingFactor();
jank_fraction_with_move_distance * SubframeWeightingFactor(); if (weighted_score_delta > 0) {
if (weighted_jank_fraction_with_move_distance > 0) { weighted_score_ += weighted_score_delta;
weighted_score_ += weighted_jank_fraction_with_move_distance; frame.Client()->DidObserveLayoutShift(weighted_score_delta,
frame.Client()->DidObserveLayoutShift( observed_input_or_scroll_);
weighted_jank_fraction_with_move_distance, observed_input_or_scroll_);
} }
} }
...@@ -345,8 +342,7 @@ void LayoutShiftTracker::NotifyPrePaintFinished() { ...@@ -345,8 +342,7 @@ void LayoutShiftTracker::NotifyPrePaintFinished() {
WindowPerformance* performance = WindowPerformance* performance =
DOMWindowPerformance::performance(*frame.DomWindow()); DOMWindowPerformance::performance(*frame.DomWindow());
if (performance) { if (performance) {
performance->AddLayoutJankFraction(jank_fraction_with_move_distance, performance->AddLayoutJankFraction(score_delta, HadRecentInput(),
HadRecentInput(),
most_recent_input_timestamp_); most_recent_input_timestamp_);
} }
} }
...@@ -425,21 +421,22 @@ bool LayoutShiftTracker::IsActive() { ...@@ -425,21 +421,22 @@ bool LayoutShiftTracker::IsActive() {
} }
std::unique_ptr<TracedValue> LayoutShiftTracker::PerFrameTraceData( std::unique_ptr<TracedValue> LayoutShiftTracker::PerFrameTraceData(
double jank_fraction, double score_delta,
double jank_fraction_with_move_distance,
double granularity_scale,
bool input_detected) const { bool input_detected) const {
auto value = std::make_unique<TracedValue>(); auto value = std::make_unique<TracedValue>();
value->SetDouble("score", jank_fraction); value->SetDouble("score", score_delta);
value->SetDouble("score_with_move_distance",
jank_fraction_with_move_distance);
value->SetDouble("cumulative_score", score_); value->SetDouble("cumulative_score", score_);
value->SetDouble("overall_max_distance", overall_max_distance_); value->SetDouble("overall_max_distance", overall_max_distance_);
value->SetDouble("frame_max_distance", frame_max_distance_); value->SetDouble("frame_max_distance", frame_max_distance_);
float granularity_scale = RegionGranularityScale(
IntRect(IntPoint(),
frame_view_->GetScrollableArea()->VisibleContentRect().Size()));
if (RuntimeEnabledFeatures::JankTrackingSweepLineEnabled()) if (RuntimeEnabledFeatures::JankTrackingSweepLineEnabled())
RegionToTracedValue(region_experimental_, granularity_scale, *value); RegionToTracedValue(region_experimental_, granularity_scale, *value);
else else
RegionToTracedValue(region_, granularity_scale, *value); RegionToTracedValue(region_, granularity_scale, *value);
value->SetBoolean("is_main_frame", frame_view_->GetFrame().IsMainFrame()); value->SetBoolean("is_main_frame", frame_view_->GetFrame().IsMainFrame());
value->SetBoolean("had_recent_input", input_detected); value->SetBoolean("had_recent_input", input_detected);
return value; return value;
......
...@@ -54,16 +54,14 @@ class CORE_EXPORT LayoutShiftTracker { ...@@ -54,16 +54,14 @@ class CORE_EXPORT LayoutShiftTracker {
} }
private: private:
void AccumulateJank(const LayoutObject&, void ObjectShifted(const LayoutObject&,
const PropertyTreeState&, const PropertyTreeState&,
FloatRect old_rect, FloatRect old_rect,
FloatRect new_rect); FloatRect new_rect);
void TimerFired(TimerBase*) {} void TimerFired(TimerBase*) {}
std::unique_ptr<TracedValue> PerFrameTraceData( std::unique_ptr<TracedValue> PerFrameTraceData(double score_delta,
double jank_fraction, bool input_detected) const;
double jank_fraction_with_move_distance, float RegionGranularityScale(const IntRect& viewport) const;
double granularity_scale,
bool input_detected) const;
double SubframeWeightingFactor() const; double SubframeWeightingFactor() const;
WebVector<gfx::Rect> ConvertIntRectsToGfxRects( WebVector<gfx::Rect> ConvertIntRectsToGfxRects(
const Vector<IntRect>& int_rects, const Vector<IntRect>& int_rects,
...@@ -76,23 +74,25 @@ class CORE_EXPORT LayoutShiftTracker { ...@@ -76,23 +74,25 @@ class CORE_EXPORT LayoutShiftTracker {
// This owns us. // This owns us.
UntracedMember<LocalFrameView> frame_view_; UntracedMember<LocalFrameView> frame_view_;
// The cumulative jank score for this LocalFrame, unweighted, with move // The document cumulative layout shift (DCLS) score for this LocalFrame,
// distance applied. // unweighted, with move distance applied.
double score_; double score_;
// The cumulative jank score for this LocalFrame, with each increase weighted // The cumulative layout shift score for this LocalFrame, with each increase
// by the extent to which the LocalFrame visibly occupied the main frame at // weighted by the extent to which the LocalFrame visibly occupied the main
// the time the jank occurred, e.g. x0.5 if the subframe occupied half of the // frame at the time the shift occurred, e.g. x0.5 if the subframe occupied
// main frame's reported size; see SubframeWeightingFactor(). // half of the main frame's reported size; see SubframeWeightingFactor().
double weighted_score_; double weighted_score_;
// The per-animation-frame jank region. // The per-animation-frame impact region.
Region region_; Region region_;
// Experimental jank region implementation using sweep-line algorithm. // Experimental impact region implementation using sweep-line algorithm.
LayoutShiftRegion region_experimental_; LayoutShiftRegion region_experimental_;
// Tracks the short period after an input event during which we ignore jank. // Tracks the short period after an input event during which we ignore shifts
// for the purpose of cumulative scoring, and report them to the web perf API
// with hadRecentInput == true.
TaskRunnerTimer<LayoutShiftTracker> timer_; TaskRunnerTimer<LayoutShiftTracker> timer_;
// The maximum distance any layout object has moved in the current animation // The maximum distance any layout object has moved in the current animation
......
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