From 8068b8e09e1f7790f7e11b3b6fb6ccd932b48670 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Jan 2019 07:22:25 +0100 Subject: [PATCH] Add a Vector::clear_with_capacity() that doesn't release the backing store. Use this for WindowManager's dirty rects to avoid kmalloc traffic. --- AK/Vector.h | 9 +++++++++ Widgets/WindowManager.cpp | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/AK/Vector.h b/AK/Vector.h index 00b134551da..984573ec7e2 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -100,6 +100,15 @@ public: m_impl = nullptr; } + void clear_with_capacity() + { + if (!m_impl) + return; + for (size_t i = 0; i < size(); ++i) + at(i).~T(); + m_impl->m_size = 0; + } + bool contains_slow(const T& value) const { for (size_t i = 0; i < size(); ++i) { diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index 1b2a5fd4c12..a45f3483f21 100644 --- a/Widgets/WindowManager.cpp +++ b/Widgets/WindowManager.cpp @@ -223,6 +223,9 @@ void WindowManager::processMouseEvent(MouseEvent& event) void WindowManager::compose() { printf("[WM] compose #%u (%u rects)\n", ++m_recompose_count, m_invalidated_rects.size()); + + dbgprintf("kmalloc stats: alloc:%u free:%u eternal:%u\n", sum_alloc, sum_free, kmalloc_sum_eternal); + auto any_window_contains_rect = [this] (const Rect& r) { for (auto* window = m_windows_in_order.head(); window; window = window->next()) { if (outerRectForWindow(window->rect()).contains(r)) @@ -235,7 +238,7 @@ void WindowManager::compose() for (auto& r : m_invalidated_rects) { if (any_window_contains_rect(r)) continue; - dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height()); + //dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height()); painter.fillRect(r, Color(0, 72, 96)); } } @@ -249,7 +252,7 @@ void WindowManager::compose() for (auto& r : m_invalidated_rects) { flush(r); } - m_invalidated_rects.clear(); + m_invalidated_rects.clear_with_capacity(); } void WindowManager::redraw_cursor() @@ -311,7 +314,7 @@ bool WindowManager::isVisible(Window& window) const void WindowManager::invalidate() { - m_invalidated_rects.clear(); + m_invalidated_rects.clear_with_capacity(); m_invalidated_rects.append(AbstractScreen::the().rect()); }