From ee4cec4ea944b965ad8a0da799a404ce2675ff10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 24 Mar 2022 11:22:44 +0100 Subject: [PATCH] SystemMonitor: Open PCI database in parallel This was causing a bunch of lag (at least half a second, very noticeable) when first opening the hardware tab, as we would only load the PCI database when initializing the widget lazily. By starting the PCI database open on another thread, we avoid this entirely, as nobody can click the hardware tab this fast :^) --- Userland/Applications/SystemMonitor/main.cpp | 35 ++++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index 5acbe69424..68c46550ea 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,17 @@ class HardwareTabWidget final : public GUI::LazyWidget { public: HardwareTabWidget() { - this->on_first_show = [](GUI::LazyWidget& self) { + auto db_creator = Threading::BackgroundAction::construct([this](auto&) { + auto db = PCIDB::Database::open(); + if (!db) + warnln("Couldn't open PCI ID database!"); + m_db = db; + m_loader_complete.store(true); + return 0; + }, + nullptr); + + this->on_first_show = [this](GUI::LazyWidget& self) { { Vector processors_field; processors_field.empend("processor", "Processor", Gfx::TextAlignment::CenterRight); @@ -123,10 +134,8 @@ public: } { - auto db = PCIDB::Database::open(); - if (!db) - warnln("Couldn't open PCI ID database!"); - + while (!m_loader_complete.load()) + ; Vector pci_fields; pci_fields.empend( "Address", Gfx::TextAlignment::CenterLeft, @@ -139,24 +148,24 @@ public: }); pci_fields.empend( "Class", Gfx::TextAlignment::CenterLeft, - [db](const JsonObject& object) { + [this](const JsonObject& object) { auto class_id = object.get("class").to_u32(); - String class_name = db ? db->get_class(class_id) : nullptr; + String class_name = m_db ? m_db->get_class(class_id) : nullptr; return class_name.is_empty() ? String::formatted("Unknown class: {:04x}", class_id) : class_name; }); pci_fields.empend( "Vendor", Gfx::TextAlignment::CenterLeft, - [db](const JsonObject& object) { + [this](const JsonObject& object) { auto vendor_id = object.get("vendor_id").to_u32(); - String vendor_name = db ? db->get_vendor(vendor_id) : nullptr; + String vendor_name = m_db ? m_db->get_vendor(vendor_id) : nullptr; return vendor_name.is_empty() ? String::formatted("Unknown vendor: {:02x}", vendor_id) : vendor_name; }); pci_fields.empend( "Device", Gfx::TextAlignment::CenterLeft, - [db](const JsonObject& object) { + [this](const JsonObject& object) { auto vendor_id = object.get("vendor_id").to_u32(); auto device_id = object.get("device_id").to_u32(); - String device_name = db ? db->get_device(vendor_id, device_id) : nullptr; + String device_name = m_db ? m_db->get_device(vendor_id, device_id) : nullptr; return device_name.is_empty() ? String::formatted("Unknown device: {:02x}", device_id) : device_name; }); pci_fields.empend( @@ -172,6 +181,10 @@ public: } }; } + +private: + RefPtr m_db; + Atomic m_loader_complete { false }; }; class StorageTabWidget final : public GUI::LazyWidget {