# HG changeset patch # User Chris Cannam # Date 1556718088 -3600 # Node ID 6cf3cb6641e1c5a7675d44ab087650f1b9153cd4 # Parent ce5f80a7c697a6044f7228a5b788a88c4b939bf1 Tweak peak-cache allocations etc in the hope of making long spectrograms a little faster to re-render diff -r ce5f80a7c697 -r 6cf3cb6641e1 layer/Colour3DPlotRenderer.cpp --- a/layer/Colour3DPlotRenderer.cpp Wed May 01 14:40:51 2019 +0100 +++ b/layer/Colour3DPlotRenderer.cpp Wed May 01 14:41:28 2019 +0100 @@ -113,7 +113,7 @@ << predicted << " (" << m_secondsPerXPixel << " x " << rect.width() << ")" << endl; #endif - if (predicted < 0.2) { + if (predicted < 0.175) { #ifdef DEBUG_COLOUR_PLOT_REPAINT SVDEBUG << "Predicted time looks fast enough: no partial renders" << endl; @@ -301,7 +301,12 @@ if (!timeConstrained && (pr != rect)) { SVCERR << "WARNING: failed to render entire requested rect " - << "even when not time-constrained" << endl; + << "even when not time-constrained: requested " + << rect.x() << "," << rect.y() << " " + << rect.width() << "x" << rect.height() << ", have " + << pr.x() << "," << pr.y() << " " + << pr.width() << "x" << pr.height() + << endl; } MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0); @@ -599,6 +604,11 @@ for (int ix = 0; in_range_for(m_sources.peakCaches, ix); ++ix) { int bpp = m_sources.peakCaches[ix]->getColumnsPerPeak(); ZoomLevel equivZoom(ZoomLevel::FramesPerPixel, binResolution * bpp); +#ifdef DEBUG_COLOUR_PLOT_REPAINT + SVDEBUG << "getPreferredPeakCache: zoomLevel = " << zoomLevel + << ", cache " << ix << " has bpp = " << bpp + << " for equivZoom = " << equivZoom << endl; +#endif if (zoomLevel >= equivZoom) { // this peak cache would work, though it might not be best if (bpp > binsPerPeak) { @@ -612,9 +622,9 @@ #ifdef DEBUG_COLOUR_PLOT_REPAINT SVDEBUG << "getPreferredPeakCache: zoomLevel = " << zoomLevel << ", binResolution " << binResolution - << ", binsPerPeak " << binsPerPeak - << ", peakCacheIndex " << peakCacheIndex << ", peakCaches " << m_sources.peakCaches.size() + << ": preferring peakCacheIndex " << peakCacheIndex + << " for binsPerPeak " << binsPerPeak << endl; #endif } @@ -1263,7 +1273,8 @@ #ifdef DEBUG_COLOUR_PLOT_REPAINT SVDEBUG << "across " << xPixelCount << " x-pixels, seconds per x-pixel = " - << m_secondsPerXPixel << endl; + << m_secondsPerXPixel << " (total = " + << (xPixelCount * m_secondsPerXPixel) << endl; #endif } } diff -r ce5f80a7c697 -r 6cf3cb6641e1 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Wed May 01 14:40:51 2019 +0100 +++ b/layer/SpectrogramLayer.cpp Wed May 01 14:41:28 2019 +0100 @@ -1411,7 +1411,10 @@ FFTModel *oldModel = m_fftModel; m_fftModel = newModel; - if (canStoreWholeCache()) { // i.e. if enough memory + bool createWholeCache = false; + checkCacheSpace(&m_peakCacheDivisor, &createWholeCache); + + if (createWholeCache) { m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1); m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor); } else { @@ -1422,12 +1425,14 @@ delete oldModel; } -bool -SpectrogramLayer::canStoreWholeCache() const +void +SpectrogramLayer::checkCacheSpace(int *suggestedPeakDivisor, + bool *createWholeCache) const { - if (!m_fftModel) { - return false; // or true, doesn't really matter - } + *suggestedPeakDivisor = 8; + *createWholeCache = false; + + if (!m_fftModel) return; size_t sz = size_t(m_fftModel->getWidth()) * @@ -1436,23 +1441,28 @@ try { SVDEBUG << "Requesting advice from StorageAdviser on whether to create whole-model cache" << endl; + // The lower amount here is the amount required for the + // slightly higher-resolution version of the peak cache + // without a whole-model cache; the higher amount is that for + // the whole-model cache. The factors of 1024 are because + // StorageAdviser rather stupidly works in kilobytes StorageAdviser::Recommendation recommendation = StorageAdviser::recommend (StorageAdviser::Criteria(StorageAdviser::SpeedCritical | StorageAdviser::PrecisionCritical | StorageAdviser::FrequentLookupLikely), - sz / 1024, sz / 1024); - if ((recommendation & StorageAdviser::UseDisc) || - (recommendation & StorageAdviser::ConserveSpace)) { + (sz / 8) / 1024, sz / 1024); + if (recommendation & StorageAdviser::UseDisc) { SVDEBUG << "Seems inadvisable to create whole-model cache" << endl; - return false; - } else { + } else if (recommendation & StorageAdviser::ConserveSpace) { + SVDEBUG << "Seems inadvisable to create whole-model cache but acceptable to use the slightly higher-resolution peak cache" << endl; + *suggestedPeakDivisor = 4; + } else { SVDEBUG << "Seems fine to create whole-model cache" << endl; - return true; + *createWholeCache = true; } } catch (const InsufficientDiscSpace &) { SVDEBUG << "Seems like a terrible idea to create whole-model cache" << endl; - return false; } } diff -r ce5f80a7c697 -r 6cf3cb6641e1 layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Wed May 01 14:40:51 2019 +0100 +++ b/layer/SpectrogramLayer.h Wed May 01 14:41:28 2019 +0100 @@ -311,8 +311,9 @@ Dense3DModelPeakCache *m_wholeCache; Dense3DModelPeakCache *m_peakCache; Dense3DModelPeakCache *getPeakCache() const { return m_peakCache; } - const int m_peakCacheDivisor; - bool canStoreWholeCache() const; + int m_peakCacheDivisor; + void checkCacheSpace(int *suggestedPeakDivisor, + bool *createWholeCache) const; void recreateFFTModel(); typedef std::map ViewMagMap; // key is view id