Skip to content

Commit

Permalink
Optimised Expression::hash().
Browse files Browse the repository at this point in the history
By storing the context names rather than querying them, we avoid having to enter python in Expression::hash(). In a test case generating a scene with 100 CustomAttributes nodes each with a python expression connected, this gives a 23% reduction in initial traversal time, and a 65% reduction in traversal time once the scene is in the ValuePlug cache.

Fixes #1034.
  • Loading branch information
johnhaddon committed Oct 14, 2014
1 parent 1d4d49b commit ff82490
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/Gaffer/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Expression : public ComputeNode
virtual void inPlugs( std::vector<std::string> &plugPaths ) = 0;
/// Must fill names with the names of all context values the expression
/// wishes to read.
virtual void contextNames( std::vector<std::string> &names ) = 0;
virtual void contextNames( std::vector<IECore::InternedString> &names ) = 0;
/// Must execute the expression in the specified context, using the values
/// provided by proxyInputs and setting the result in proxyOutput.
virtual void execute( const Context *context, const std::vector<const ValuePlug *> &proxyInputs, ValuePlug *proxyOutput ) = 0;
Expand Down Expand Up @@ -112,6 +112,7 @@ class Expression : public ComputeNode
void updatePlugs( const std::string &outPlugPath, std::vector<std::string> &inPlugPaths );

EnginePtr m_engine;
std::vector<IECore::InternedString> m_contextNames;

};

Expand Down
6 changes: 3 additions & 3 deletions src/Gaffer/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ void Expression::hash( const ValuePlug *output, const Context *context, IECore::
}
if( m_engine )
{
std::vector<std::string> contextNames;
m_engine->contextNames( contextNames );
for( std::vector<std::string>::const_iterator it = contextNames.begin(); it != contextNames.end(); it++ )
for( std::vector<IECore::InternedString>::const_iterator it = m_contextNames.begin(); it != m_contextNames.end(); it++ )
{
const IECore::Data *d = context->get<IECore::Data>( *it, 0 );
if( d )
Expand Down Expand Up @@ -209,6 +207,8 @@ void Expression::plugSet( Plug *plug )
{
m_engine->inPlugs( inPlugPaths );
outPlugPath = m_engine->outPlug();
m_contextNames.clear();
m_engine->contextNames( m_contextNames );
}

updatePlugs( outPlugPath, inPlugPaths );
Expand Down
2 changes: 1 addition & 1 deletion src/GafferBindings/ExpressionBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class EngineWrapper : public Expression::Engine, public IECorePython::Wrapper<Ex
}
}

virtual void contextNames( std::vector<std::string> &names )
virtual void contextNames( std::vector<IECore::InternedString> &names )
{
IECorePython::ScopedGILLock gilLock;
try
Expand Down

0 comments on commit ff82490

Please sign in to comment.