Skip to content

Commit

Permalink
Render : Improve cache clearing
Browse files Browse the repository at this point in the history
- Only clear caches for whitelisted apps.
- Clear per-thread hash caches via `now = true`.
  • Loading branch information
johnhaddon committed Jul 10, 2023
1 parent fff8815 commit 8a997bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Improvements
- Ancestors and siblings of locations included in the Visible Set are no longer drawn while their ancestors are collapsed.
- Added red wireframe colour to the bounding box of locations excluded from the Visible Set.
- HierarchyView : Added support for inclusion and exclusion of leaf level locations to the Visible Set.
- Render : Improved clearing of the compute and hash caches prior to rendering, potentially providing more memory to the renderer. Note that clearing is now only performed in the `execute` and `dispatch` apps.

Fixes
-----
Expand Down
26 changes: 16 additions & 10 deletions src/GafferScene/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "GafferScene/ScenePlug.h"
#include "GafferScene/SceneProcessor.h"

#include "Gaffer/ApplicationRoot.h"
#include "Gaffer/MonitorAlgo.h"
#include "Gaffer/PerformanceMonitor.h"

Expand Down Expand Up @@ -336,16 +337,21 @@ void Render::executeInternal( bool flushCaches ) const
if( flushCaches )
{
// Now we have generated the scene, flush Cortex and Gaffer caches to
// provide more memory to the renderer.
/// \todo If executing directly within the gui app flushing the caches
/// is definitely not wanted. Since this scenario is currently uncommon,
/// we prioritise the common case of performing a single render from within
/// `gaffer execute`, but it would be good to do better.
ObjectPool::defaultObjectPool()->clear();
ValuePlug::clearCache();
/// \todo This is not as effective as it could be, because it doesn't actually
/// clear the per-thread caches until the next operation on each thread.
ValuePlug::clearHashCache();
// provide more memory to the renderer. We limit this to the `execute`
// and `dispatch` applications for two reasons :
//
// - In a GUI application, we don't want to clear the caches because
// we'll probably benefit from using them again later.
// - In `execute` and `dispatch` we know we're not executing concurrently
// with anything else, and can therefore pass `now = true` to
// `clearHashCache()` safely.
auto *application = ancestor<ApplicationRoot>();
if( application && ( application->getName() == "execute" || application->getName() == "dispatch" ) )
{
ObjectPool::defaultObjectPool()->clear();
ValuePlug::clearCache();
ValuePlug::clearHashCache( /* now = */ true );
}
}

renderer->render();
Expand Down

0 comments on commit 8a997bc

Please sign in to comment.