diff --git a/base/logging.cc b/base/logging.cc index 80dab7dd037f4..6ec8576ca34a9 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -210,16 +210,6 @@ void MaybeWarnVmodule() { #endif // !BUILDFLAG(USE_RUNTIME_VLOG) && DCHECK_IS_ON() -const char* const log_severity_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; -static_assert(LOGGING_NUM_SEVERITIES == std::size(log_severity_names), - "Incorrect number of log_severity_names"); - -const char* log_severity_name(int severity) { - if (severity >= 0 && severity < LOGGING_NUM_SEVERITIES) - return log_severity_names[severity]; - return "UNKNOWN"; -} - // Specifies the process' logging sink(s), represented as a combination of // LoggingDestination values joined by bitwise OR. uint32_t g_logging_destination = LOG_DEFAULT; @@ -270,30 +260,6 @@ base::stack& GetLogAssertHandlerStack() { // A log message handler that gets notified of every log message we process. LogMessageHandlerFunction g_log_message_handler = nullptr; -uint64_t TickCount() { -#if BUILDFLAG(IS_WIN) - return GetTickCount(); -#elif BUILDFLAG(IS_FUCHSIA) - return static_cast( - zx_clock_get_monotonic() / - static_cast(base::Time::kNanosecondsPerMicrosecond)); -#elif BUILDFLAG(IS_APPLE) - return mach_absolute_time(); -#elif BUILDFLAG(IS_NACL) - // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h - // So we have to use clock() for now. - return clock(); -#elif BUILDFLAG(IS_POSIX) - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - - uint64_t absolute_micro = static_cast(ts.tv_sec) * 1000000 + - static_cast(ts.tv_nsec) / 1000; - - return absolute_micro; -#endif -} - void DeleteFilePath(const PathString& log_name) { #if BUILDFLAG(IS_WIN) DeleteFile(log_name.c_str()); @@ -939,57 +905,12 @@ void LogMessage::Init(const char* file, int line) { } else #endif // BUILDFLAG(IS_CHROMEOS) { - // TODO(darin): It might be nice if the columns were fixed width. stream_ << '['; - if (g_log_prefix) - stream_ << g_log_prefix << ':'; - if (g_log_process_id) - stream_ << base::GetUniqueIdForProcess() << ':'; - if (g_log_thread_id) - stream_ << base::PlatformThread::CurrentId() << ':'; - if (g_log_timestamp) { -#if BUILDFLAG(IS_WIN) - SYSTEMTIME local_time; - GetLocalTime(&local_time); - stream_ << std::setfill('0') - << std::setw(2) << local_time.wMonth - << std::setw(2) << local_time.wDay - << '/' - << std::setw(2) << local_time.wHour - << std::setw(2) << local_time.wMinute - << std::setw(2) << local_time.wSecond - << '.' - << std::setw(3) << local_time.wMilliseconds - << ':'; -#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) - timeval tv; - gettimeofday(&tv, nullptr); - time_t t = tv.tv_sec; - struct tm local_time; - localtime_r(&t, &local_time); - struct tm* tm_time = &local_time; - stream_ << std::setfill('0') - << std::setw(2) << 1 + tm_time->tm_mon - << std::setw(2) << tm_time->tm_mday - << '/' - << std::setw(2) << tm_time->tm_hour - << std::setw(2) << tm_time->tm_min - << std::setw(2) << tm_time->tm_sec - << '.' - << std::setw(6) << tv.tv_usec - << ':'; -#else -#error Unsupported platform -#endif - } - if (g_log_tickcount) - stream_ << TickCount() << ':'; - if (severity_ >= 0) { - stream_ << log_severity_name(severity_); - } else { - stream_ << "VERBOSE" << -severity_; - } - stream_ << ":" << filename << "(" << line << ")] "; + stream_ << filename; + stream_ << std::setw(24 - (int)filename.length()) << " "; + stream_ << " "; + stream_ << std::setw(4) << line; + stream_ << "] "; } message_start_ = stream_.str().length(); } diff --git a/third_party/blink/renderer/core/dom/node.cc b/third_party/blink/renderer/core/dom/node.cc index f1e42bf7b75e1..ca952936a686d 100644 --- a/third_party/blink/renderer/core/dom/node.cc +++ b/third_party/blink/renderer/core/dom/node.cc @@ -2287,6 +2287,9 @@ String Node::DebugName() const { name.Append('\''); } } + name.Append(" ("); + name.Append(ToString()); + name.Append(")"); return name.ReleaseString(); } diff --git a/third_party/blink/renderer/core/frame/local_frame_view.cc b/third_party/blink/renderer/core/frame/local_frame_view.cc index 767b6bb562920..a72ed8007f990 100644 --- a/third_party/blink/renderer/core/frame/local_frame_view.cc +++ b/third_party/blink/renderer/core/frame/local_frame_view.cc @@ -2867,6 +2867,7 @@ void LocalFrameView::EnqueueScrollEvents() { bool LocalFrameView::PaintTree(PaintBenchmarkMode benchmark_mode, PaintControllerCycleScope& cycle_scope) { + DVLOG(1) << ">>> LocalFrameView::PaintTree"; SCOPED_UMA_AND_UKM_TIMER(EnsureUkmAggregator(), LocalFrameUkmAggregator::kPaint); diff --git a/third_party/blink/renderer/platform/graphics/paint/paint_chunk.cc b/third_party/blink/renderer/platform/graphics/paint/paint_chunk.cc index 42862df570fcb..2969494280b89 100644 --- a/third_party/blink/renderer/platform/graphics/paint/paint_chunk.cc +++ b/third_party/blink/renderer/platform/graphics/paint/paint_chunk.cc @@ -28,6 +28,7 @@ bool PointerValueEquals(const std::unique_ptr& a, struct SameSizeAsPaintChunk { wtf_size_t begin_index; wtf_size_t end_index; + wtf_size_t cached_count; Color background_color; float background_color_area; PaintChunk::Id id; @@ -43,6 +44,37 @@ struct SameSizeAsPaintChunk { ASSERT_SIZE(PaintChunk, SameSizeAsPaintChunk); +PaintChunk::PaintChunk(wtf_size_t begin, + wtf_size_t end, + const DisplayItemClient& client, + const Id& id, + const PropertyTreeStateOrAlias& props, + bool effectively_invisible) + : begin_index(begin), + end_index(end), + background_color(Color::kTransparent), + background_color_area(0u), + id(id), + properties(props), + text_known_to_be_on_opaque_background(true), + has_text(false), + is_cacheable(client.IsCacheable()), + client_is_just_created(client.IsJustCreated()), + is_moved_from_cached_subsequence(false), + effectively_invisible(effectively_invisible) { + DVLOG(1) << ">>> PaintChunk" + << " this=" << this << " client=" << client.DebugName(); +} + +bool PaintChunk::ContainsMostlyCachedDisplayItems() const { + float cached = cached_count; + float total = size(); + DVLOG(1) << " ContainsMostlyCachedDisplayItems" + << " this=" << this << " cached=" << cached << " total=" << total; + DVLOG(2) << ToString(); + return (cached / total) >= 0.5f; +} + bool PaintChunk::EqualsForUnderInvalidationChecking( const PaintChunk& other) const { return size() == other.size() && id == other.id && diff --git a/third_party/blink/renderer/platform/graphics/paint/paint_chunk.h b/third_party/blink/renderer/platform/graphics/paint/paint_chunk.h index c25e65f677038..d428a6047ae2f 100644 --- a/third_party/blink/renderer/platform/graphics/paint/paint_chunk.h +++ b/third_party/blink/renderer/platform/graphics/paint/paint_chunk.h @@ -41,19 +41,7 @@ struct PLATFORM_EXPORT PaintChunk { const DisplayItemClient& client, const Id& id, const PropertyTreeStateOrAlias& props, - bool effectively_invisible = false) - : begin_index(begin), - end_index(end), - background_color(Color::kTransparent), - background_color_area(0u), - id(id), - properties(props), - text_known_to_be_on_opaque_background(true), - has_text(false), - is_cacheable(client.IsCacheable()), - client_is_just_created(client.IsJustCreated()), - is_moved_from_cached_subsequence(false), - effectively_invisible(effectively_invisible) {} + bool effectively_invisible = false); // Move a paint chunk from a cached subsequence. PaintChunk(wtf_size_t begin, PaintChunk&& other) @@ -89,14 +77,22 @@ struct PLATFORM_EXPORT PaintChunk { return old.is_cacheable && Matches(old.id); } + bool ContainsMostlyCachedDisplayItems() const; + bool OldCanMatchOldChunk() const { + return is_cacheable && !client_is_just_created; + } bool CanMatchOldChunk() const { if (!is_cacheable) return false; + // A chunk whose client is just created should not match any cached chunk, // even if it's id equals the old chunk's id (which may happen if this // chunk's client is just created at the same address of the old chunk's // deleted client). - return !client_is_just_created; + if (client_is_just_created) + return false; + + return ContainsMostlyCachedDisplayItems(); } bool Matches(const Id& other_id) const { @@ -135,6 +131,8 @@ struct PLATFORM_EXPORT PaintChunk { // |endIndex - beginIndex| drawings in the chunk. wtf_size_t end_index; + wtf_size_t cached_count = 0; + // Color to use for checkerboarding, derived from display item's in this // chunk; or Color::kTransparent if no such display item exists. Color background_color; diff --git a/third_party/blink/renderer/platform/graphics/paint/paint_chunker.cc b/third_party/blink/renderer/platform/graphics/paint/paint_chunker.cc index 6413214b23aed..6cddb65a4f043 100644 --- a/third_party/blink/renderer/platform/graphics/paint/paint_chunker.cc +++ b/third_party/blink/renderer/platform/graphics/paint/paint_chunker.cc @@ -95,6 +95,8 @@ bool PaintChunker::EnsureCurrentChunk(const PaintChunk::Id& id, if (WillForceNewChunk() || current_properties_ != chunks_->back().properties) { + DVLOG(1) << " EnsureCurrentChunk new chunk!" + << " client=" << client.DebugName(); if (!next_chunk_id_) { next_chunk_id_.emplace(id, client); } @@ -112,7 +114,8 @@ bool PaintChunker::EnsureCurrentChunk(const PaintChunk::Id& id, } bool PaintChunker::IncrementDisplayItemIndex(const DisplayItemClient& client, - const DisplayItem& item) { + const DisplayItem& item, + bool was_cached) { DCHECK(chunks_); bool item_forces_new_chunk = item.IsForeignLayer() || item.IsScrollbar(); @@ -159,6 +162,11 @@ bool PaintChunker::IncrementDisplayItemIndex(const DisplayItemClient& client, std::max(chunk.raster_effect_outset, item.GetRasterEffectOutset()); chunk.end_index++; + if (was_cached) + chunk.cached_count++; + DVLOG(1) << " IncrementDisplayItemIndex" + << " &chunk=" << &chunk; + chunk.ContainsMostlyCachedDisplayItems(); // When forcing a new chunk, we still need to force new chunk for the next // display item. Otherwise reset force_new_chunk_ to false. diff --git a/third_party/blink/renderer/platform/graphics/paint/paint_chunker.h b/third_party/blink/renderer/platform/graphics/paint/paint_chunker.h index f9863c6883ecb..aed39941f60ba 100644 --- a/third_party/blink/renderer/platform/graphics/paint/paint_chunker.h +++ b/third_party/blink/renderer/platform/graphics/paint/paint_chunker.h @@ -66,7 +66,9 @@ class PLATFORM_EXPORT PaintChunker final { void AppendByMoving(PaintChunk&&); // Returns true if a new chunk is created. - bool IncrementDisplayItemIndex(const DisplayItemClient&, const DisplayItem&); + bool IncrementDisplayItemIndex(const DisplayItemClient&, + const DisplayItem&, + bool was_cached); // The id will be used when we need to create a new current chunk. // Otherwise it's ignored. Returns true if a new chunk is added. diff --git a/third_party/blink/renderer/platform/graphics/paint/paint_controller.cc b/third_party/blink/renderer/platform/graphics/paint/paint_controller.cc index 0577f1c4780b5..3ec9428aa339e 100644 --- a/third_party/blink/renderer/platform/graphics/paint/paint_controller.cc +++ b/third_party/blink/renderer/platform/graphics/paint/paint_controller.cc @@ -160,7 +160,7 @@ bool PaintController::UseCachedItemIfPossible(const DisplayItemClient& client, new_paint_artifact_->GetDisplayItemList().AppendByMoving( current_paint_artifact_->GetDisplayItemList()[cached_item]); new_item.SetPaintInvalidationReason(PaintInvalidationReason::kNone); - ProcessNewItem(client, new_item); + ProcessNewItem(client, new_item, true); return true; } @@ -342,7 +342,11 @@ void PaintController::MarkClientForValidation(const DisplayItemClient& client) { } void PaintController::ProcessNewItem(const DisplayItemClient& client, - DisplayItem& display_item) { + DisplayItem& display_item, + bool was_cached) { + DVLOG(1) << " ProcessNewItem" + << " client=" << &client << " display_item=" << &display_item + << " was_cached=" << was_cached << " (" << client.DebugName() << ")"; if (IsSkippingCache() && usage_ == kMultiplePaints) { client.Invalidate(PaintInvalidationReason::kUncacheable); display_item.SetPaintInvalidationReason( @@ -350,7 +354,8 @@ void PaintController::ProcessNewItem(const DisplayItemClient& client, } RecordDebugInfo(client); - if (paint_chunker_.IncrementDisplayItemIndex(client, display_item)) + if (paint_chunker_.IncrementDisplayItemIndex(client, display_item, + was_cached)) CheckNewChunk(); if (!frame_first_paints_.back().first_painted && display_item.IsDrawing() && @@ -705,7 +710,7 @@ void PaintController::FinishCycle() { chunk.client_is_just_created = false; #if DCHECK_IS_ON() - if (VLOG_IS_ON(1)) { + if (VLOG_IS_ON(3)) { VLOG(1) << "PaintController::FinishCycle() completed"; if (VLOG_IS_ON(3)) ShowDebugDataWithPaintRecords(); diff --git a/third_party/blink/renderer/platform/graphics/paint/paint_controller.h b/third_party/blink/renderer/platform/graphics/paint/paint_controller.h index 188bdc848d22b..40bdc0ad3f5c7 100644 --- a/third_party/blink/renderer/platform/graphics/paint/paint_controller.h +++ b/third_party/blink/renderer/platform/graphics/paint/paint_controller.h @@ -153,7 +153,7 @@ class PLATFORM_EXPORT PaintController { .AllocateAndConstruct( client.Id(), std::forward(args)...); display_item.SetFragment(current_fragment_); - ProcessNewItem(client, display_item); + ProcessNewItem(client, display_item, false); } // Tries to find the cached display item corresponding to the given @@ -319,7 +319,7 @@ class PLATFORM_EXPORT PaintController { void InvalidateAllForTesting(); // Set new item state (cache skipping, etc) for the last new display item. - void ProcessNewItem(const DisplayItemClient&, DisplayItem&); + void ProcessNewItem(const DisplayItemClient&, DisplayItem&, bool was_cached); void CheckNewItem(DisplayItem&); void CheckNewChunkId(const PaintChunk::Id&); diff --git a/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.cc b/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.cc index fd6126c738c79..6c1d8e38c5482 100644 --- a/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.cc +++ b/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.cc @@ -42,15 +42,23 @@ const PaintChunk& RasterInvalidator::GetOldChunk(wtf_size_t index) const { wtf_size_t RasterInvalidator::MatchNewChunkToOldChunk( const PaintChunk& new_chunk, - wtf_size_t old_index) const { + wtf_size_t old_index, + wtf_size_t& match_counter) const { + if (new_chunk.OldCanMatchOldChunk() && + !new_chunk.ContainsMostlyCachedDisplayItems()) { + DVLOG(1) << " MatchNewChunkToOldChunk" + << " will save " << old_paint_chunks_info_.size(); + } if (!new_chunk.CanMatchOldChunk()) return kNotFound; for (wtf_size_t i = old_index; i < old_paint_chunks_info_.size(); i++) { + match_counter++; if (new_chunk.Matches(GetOldChunk(i))) return i; } for (wtf_size_t i = 0; i < old_index; i++) { + match_counter++; if (new_chunk.Matches(GetOldChunk(i))) return i; } @@ -184,13 +192,29 @@ void RasterInvalidator::GenerateRasterInvalidations( old_chunks_matched.resize(old_paint_chunks_info_.size()); wtf_size_t old_index = 0; wtf_size_t max_matched_old_index = 0; + wtf_size_t match_counter = 0; + DVLOG(1) << " >>> GenerateRasterInvalidations" + << " |old|=" << old_paint_chunks_info_.size() + << " |new|=" << new_chunks.size(); for (auto it = new_chunks.begin(); it != new_chunks.end(); ++it) { + DVLOG(4) << " " + << " &new_chunk=" << &*it + << " ShouldSkip=" << ShouldSkipForRasterInvalidation(it) << " (" + << it->id.ToString().Utf8() << ")"; if (ShouldSkipForRasterInvalidation(it)) continue; const auto& new_chunk = *it; - auto matched_old_index = MatchNewChunkToOldChunk(new_chunk, old_index); + auto matched_old_index = + MatchNewChunkToOldChunk(new_chunk, old_index, match_counter); + DVLOG(3) << " " + << " &new_chunk=" << &new_chunk + << " kNotFound?=" << (matched_old_index == kNotFound) << " (" + << new_chunk.id.ToString().Utf8() << ")"; if (matched_old_index == kNotFound) { + if (new_chunk.CanMatchOldChunk()) + DVLOG(2) << " " + << " fail! " << new_chunk.id.ToString().Utf8(); // The new chunk doesn't match any old chunk. mapper.SwitchToChunk(new_chunk); auto& new_chunk_info = new_chunks_info.emplace_back(*this, mapper, it); @@ -280,6 +304,8 @@ void RasterInvalidator::GenerateRasterInvalidations( old_index = 0; max_matched_old_index = std::max(max_matched_old_index, matched_old_index); } + DVLOG(1) << " " + << " match_counter=" << match_counter; // Invalidate remaining unmatched (disappeared or uncacheable) old chunks. for (wtf_size_t i = 0; i < old_paint_chunks_info_.size(); ++i) { diff --git a/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.h b/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.h index 92de1b9dc9f0e..29e82ef9d00ff 100644 --- a/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.h +++ b/third_party/blink/renderer/platform/graphics/paint/raster_invalidator.h @@ -112,7 +112,8 @@ class PLATFORM_EXPORT RasterInvalidator { ALWAYS_INLINE const PaintChunk& GetOldChunk(wtf_size_t index) const; ALWAYS_INLINE wtf_size_t MatchNewChunkToOldChunk(const PaintChunk& new_chunk, - wtf_size_t old_index) const; + wtf_size_t old_index, + wtf_size_t&) const; ALWAYS_INLINE void IncrementallyInvalidateChunk( RasterInvalidationFunction,