Salome HOME
No more copy, between PyBytes and CORBA sequence. Reduce Memory peak by spliting...
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 8 Apr 2020 05:22:27 +0000 (07:22 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 8 Apr 2020 08:56:01 +0000 (10:56 +0200)
src/runtime/AutoGIL.hxx
src/runtime/PythonNode.cxx

index 965743f67e4484c1e2e1e5720e977a91d55d21a2..d9e94b98644f14f396232074010535cd429f2eec 100644 (file)
@@ -39,7 +39,7 @@ namespace YACS
     class AutoPyRef
     {
     public:
-      AutoPyRef(PyObject *pyobj=0):_pyobj(pyobj) { }
+      AutoPyRef(PyObject *pyobj=nullptr):_pyobj(pyobj) { }
       ~AutoPyRef() { release(); }
       AutoPyRef(const AutoPyRef& other):_pyobj(other._pyobj) { if(_pyobj) Py_XINCREF(_pyobj); }
       AutoPyRef& operator=(const AutoPyRef& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; Py_XINCREF(_pyobj); return *this; }
index f79e1780c76da9b28b0200c54adf3353c323646f..d9b06c43a0206cd778cd744f7eb14ae317417ba9 100644 (file)
@@ -410,6 +410,7 @@ void PythonNode::executeRemote()
     }
   //
   std::unique_ptr<Engines::pickledArgs> serializationInputCorba(new Engines::pickledArgs);
+  AutoPyRef serializationInput;
   {
       AutoGIL agil;
       PyObject *args(0),*ob(0);
@@ -430,17 +431,15 @@ void PythonNode::executeRemote()
       PyObject_Print(args,stderr,Py_PRINT_RAW);
       std::cerr << endl;
 #endif
-      PyObject *serializationInput(PyObject_CallFunctionObjArgs(_pyfuncSer,args,NULL));
+      serializationInput.set(PyObject_CallFunctionObjArgs(_pyfuncSer,args,nullptr));
       Py_DECREF(args);
       //The pickled string may contain NULL characters so use PyString_AsStringAndSize
       char *serializationInputC(0);
       Py_ssize_t len;
       if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
         throw Exception("DistributedPythonNode problem in python pickle");
-      serializationInputCorba->length(len);
-      for(int i=0; i < len ; i++)
-        (*serializationInputCorba.get())[i]=serializationInputC[i];
-      Py_DECREF(serializationInput);
+      // no copy here. The C byte array of Python is taken  as this into CORBA sequence to avoid copy
+      serializationInputCorba.reset(new Engines::pickledArgs(len,len,reinterpret_cast<CORBA::Octet *>(serializationInputC),0));
   }
 
   //get the list of output argument names
@@ -465,7 +464,10 @@ void PythonNode::executeRemote()
   try
     {
       //pass outargsname and dict serialized
-      resultCorba=_pynode->execute(myseq,*(serializationInputCorba.get()));
+      _pynode->executeFirst(*(serializationInputCorba.get()));
+      //serializationInput and serializationInputCorba are no more needed for server. Release it.
+      serializationInputCorba.reset(nullptr); serializationInput.set(nullptr);
+      resultCorba=_pynode->executeSecond(myseq);
     }
   catch( const SALOME::SALOME_Exception& ex )
     {
@@ -479,7 +481,6 @@ void PythonNode::executeRemote()
     {
       _pynode->UnRegister();
     }
-  serializationInputCorba.reset(nullptr);
   _pynode = Engines::PyScriptNode::_nil();
   //
   bool dummy;