From 2423936eda7d097e56ec5c79b83ef4dbc153da1e Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 21 Jun 2023 09:05:03 +0200 Subject: [PATCH] Optimize usage of context for PythonNode (by deleting input and output port PyObject) in local execution mode. --- src/runtime/PythonNode.cxx | 11 +++++++++++ src/yacsloader/Test/YacsLoaderTest.cxx | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/runtime/PythonNode.cxx b/src/runtime/PythonNode.cxx index d0f40b944..cbc2ff4df 100644 --- a/src/runtime/PythonNode.cxx +++ b/src/runtime/PythonNode.cxx @@ -780,6 +780,8 @@ void PythonNode::executeLocal() cerr << endl; #endif p->put(ob); + if(!isUsingPythonCache()) + PyDict_DelItemString(_context,p->getName().c_str()); } } catch(ConversionException& ex) @@ -790,6 +792,15 @@ void PythonNode::executeLocal() if(_autoSqueeze) squeezeMemory(); DEBTRACE( "-----------------End PyNode::outputs-----------------" ); + if(!isUsingPythonCache()) + { + for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++) + { + AutoPyRef pStr = PyUnicode_FromString( (*iter2)->getName().c_str() ); + if( PyDict_Contains(_context,pStr) == 1 ) + { PyDict_DelItem(_context,pStr); } + } + } } DEBTRACE( "++++++++++++++ End PyNode::execute: " << getName() << " ++++++++++++++++++++" ); } diff --git a/src/yacsloader/Test/YacsLoaderTest.cxx b/src/yacsloader/Test/YacsLoaderTest.cxx index 43df387c8..109145e8a 100644 --- a/src/yacsloader/Test/YacsLoaderTest.cxx +++ b/src/yacsloader/Test/YacsLoaderTest.cxx @@ -654,7 +654,7 @@ void YacsLoaderTest::refcnt() ret = driverTest(p, "samples/refcnt2.xml"); CPPUNIT_ASSERT(ret == 0); data = ((OutputPyPort*)p->nodeMap["b1.b.node1"]->getOutputPort("p1"))->get(); - CPPUNIT_ASSERT(data->ob_refcnt==19); + CPPUNIT_ASSERT_EQUAL(data->ob_refcnt,(long int)13); } void YacsLoaderTest::foreachs() -- 2.39.2