Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValuePlug : Stop getValueInternal() ignoring precomputedHash #5522

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions python/GafferTest/NumericPlugTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,14 @@ def testPrecomputedHash( self ) :
self.assertEqual( n.numComputeCalls, 1 )

h = n["sum"].hash()
numHashCalls = n.numHashCalls
# Accept either 1 or 2 - it would be reasonable for the ValuePlug
# to have either cached the hash or not, but that's not what we're
# testing here.
self.assertTrue( numHashCalls == 1 or numHashCalls == 2 )
self.assertEqual( n.numHashCalls, 1 )
self.assertEqual( n.numComputeCalls, 1 )

# What we care about is that calling getValue() with a precomputed hash
# definitely doesn't recompute the hash again.
# Calling `getValue()`` with a precomputed hash shouldn't recompute the
# hash again, even if it has been cleared from the cache.
Gaffer.ValuePlug.clearHashCache()
self.assertEqual( n["sum"].getValue( _precomputedHash = h ), 30 )
self.assertEqual( n.numHashCalls, numHashCalls )
self.assertEqual( n.numHashCalls, 1 )
self.assertEqual( n.numComputeCalls, 1 )

def testIsSetToDefault( self ) :
Expand Down
13 changes: 5 additions & 8 deletions python/GafferTest/TypedPlugTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,14 @@ def testPrecomputedHash( self ) :
self.assertEqual( n.numComputeCalls, 1 )

h = n["out"].hash()
numHashCalls = n.numHashCalls
# Accept either 1 or 2 - it would be reasonable for the ValuePlug
# to have either cached the hash or not, but that's not what we're
# testing here.
self.assertTrue( numHashCalls == 1 or numHashCalls == 2 )
self.assertEqual( n.numHashCalls, 1 )
self.assertEqual( n.numComputeCalls, 1 )

# What we care about is that calling getValue() with a precomputed hash
# definitely doesn't recompute the hash again.
# Calling `getValue()` with a precomputed hash shouldn't recompute the
# hash again, even if it has been cleared from the cache.
Gaffer.ValuePlug.clearHashCache()
self.assertEqual( n["out"].getValue( _precomputedHash = h ), "hi" )
self.assertEqual( n.numHashCalls, numHashCalls )
self.assertEqual( n.numHashCalls, 1 )
self.assertEqual( n.numComputeCalls, 1 )

def testBoolPlugStringConnections( self ) :
Expand Down
16 changes: 6 additions & 10 deletions python/GafferTest/ValuePlugTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,18 @@ def testPrecomputedHashOptimisation( self ) :
self.assertEqual( a1, IECore.StringData( "a" ) )
self.assertEqual( n.numHashCalls, 1 )

# We apply some leeway in our test for how many hash calls are
# made - a good ValuePlug implementation will probably avoid
# unecessary repeated calls in most cases, but it's not
# what this unit test is about.
a2 = n["out"].getValue( _copy = False )
self.assertTrue( a2.isSame( a1 ) )
self.assertTrue( n.numHashCalls == 1 or n.numHashCalls == 2 )
self.assertEqual( n.numHashCalls, 1 )

h = n["out"].hash()
self.assertTrue( n.numHashCalls >= 1 and n.numHashCalls <= 3 )
numHashCalls = n.numHashCalls
self.assertEqual( n.numHashCalls, 1 )

# What we care about is that calling getValue() with a precomputed hash
# definitely doesn't recompute the hash again.
# Calling `getValue()` with a precomputed hash shouldn't recompute the
# hash again, even if it has been cleared from the cache.
Gaffer.ValuePlug.clearHashCache()
a3 = n["out"].getValue( _copy = False, _precomputedHash = h )
self.assertEqual( n.numHashCalls, numHashCalls )
self.assertEqual( n.numHashCalls, 1 )
self.assertTrue( a3.isSame( a1 ) )

def testSerialisationOfChildValues( self ) :
Expand Down
2 changes: 1 addition & 1 deletion src/Gaffer/ValuePlug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ class ValuePlug::ComputeProcess : public Process
// > `StringPlug::hash()` account for additional processing (such as
// > substitutions) performed in public `getValue()` methods _after_
// > calling `getValueInternal()`.
const IECore::MurmurHash hash = p->ValuePlug::hash();
const IECore::MurmurHash hash = precomputedHash ? *precomputedHash : p->ValuePlug::hash();

if( !Process::forceMonitoring( threadState, plug, staticType ) )
{
Expand Down
Loading