From 55d3bda18a8f929d19557ec0d215eef66c68506b Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 9 Jul 2025 19:04:30 -0700 Subject: [DSC] Performance improvements and clean-up in SymbolTableView Avoid copying the vector of symbols where possible. When no filter string is applied we no longer copy the entire vector symbols by having the symbols used for display be indirected via a pointer. It points either to the unfiltered symbols or the filtered symbols. Some unncessary copies have been removed by using `std::move` where appropriate. Filtering has been updated to avoid `std::vector::reserve` / `std::vector::shrink_to_fit` in favor of letting the filtered vector control its own growth and reuse its buffer. This avoids allocating a ~100MB buffer every time we update the filter only to later reallocate and move the contents into a smaller buffer. Instead the buffer grows via `std::vector`'s usual growth algorithm and it is preserved across filter calls to avoid unnecessarily reallocating it, and only shrink the buffer if it has shrunk significantly vs previous iterations. --- view/sharedcache/ui/symboltable.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'view/sharedcache/ui/symboltable.h') diff --git a/view/sharedcache/ui/symboltable.h b/view/sharedcache/ui/symboltable.h index 51ba88f0..9c7a1eab 100644 --- a/view/sharedcache/ui/symboltable.h +++ b/view/sharedcache/ui/symboltable.h @@ -19,9 +19,12 @@ Q_OBJECT SymbolTableView* m_parent; QFont m_font; std::string m_filter; - std::vector m_preparedSymbols{}; - // These are the symbols we actually use - std::vector m_modelSymbols{}; + + std::vector m_symbols; + std::vector m_filteredSymbols; + + // A pointer to either m_symbols or m_filteredSymbols, depending on whether a filter is applied. + std::vector *m_displaySymbols = nullptr; public: explicit SymbolTableModel(SymbolTableView* parent); @@ -31,10 +34,11 @@ public: QVariant data(const QModelIndex& index, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; void sort(int column, Qt::SortOrder order) override; - void updateSymbols(std::vector&& symbols); + + void updateSymbols(std::vector symbols); void setFilter(std::string text); - const SharedCacheAPI::CacheSymbol& symbolAt(int row) const; + const SharedCacheAPI::CacheSymbol& symbolAt(int row) const; }; -- cgit v1.3.1