Menu

Performance improvement for persistence

paul
2017-03-30
2017-03-30
  • paul

    paul - 2017-03-30

    Hello,

    Here's a patch (sorry, not based on your trunk) that significantly improves the time it takes to write a large number (100K+) objects:

    Index: objstrm.cpp
    ===================================================================
    --- objstrm.cpp (revision 77)
    +++ objstrm.cpp (revision 78)
    @@ -32,6 +32,8 @@
     #if !defined(OWL_EXCEPT_H)
     #include <owl/except.h>
     #endif
    +#include <set>
    +
     extern void __Trace(LPCSTR lpszFormat, ...);
     inline void __NoTrace(LPCSTR lpszFormat, ...){}
     #if 0
    @@ -141,7 +143,7 @@
     {
       //_TRACE("__TStreamableCont::DestroyTypes() Create Types\n");
       // not locking because this functions is called from UnregisterTypes()
    -  // and Lock already applyed
    +  // and Lock already applied
       //LOCKTYPES 
       delete Types;
       Types = 0;
    @@ -207,12 +209,35 @@
       return (int)NPOS;
     }
     //
    +/*
     class TSortedTPWObjObjectArray: public TSortedObjectArray<TPWrittenObjects::TPWObj>{
       public:
         TSortedTPWObjObjectArray(int a, int b=0, int c=0): TSortedObjectArray<TPWrittenObjects::TPWObj>(a,b,c){}
         TSortedTPWObjObjectArray(){}
     };
    +*/
    
    +// Use a std::set for faster insertion and lookup. The Borland sorted arrays
    +// have very poor performance for large numbers of items (O(n^2)).
    +class TSortedTPWObjObjectArray
    +{
    +public:
    +   TSortedTPWObjObjectArray(int) {}
    +   ~TSortedTPWObjObjectArray() { m_Items.clear(); }
    +   void Flush() { m_Items.clear(); }
    +   void Add(TPWrittenObjects::TPWObj obj) { m_Items.insert(obj); }
    +   P_id_type Find(TPWrittenObjects::TPWObj obj)
    +   {
    +       std::set<TPWrittenObjects::TPWObj>::const_iterator i = m_Items.find(obj);
    +       if(i != m_Items.end()) {
    +           return i->Ident;
    +       }
    +       return 0;
    +   }
    +private:
    +   std::set<TPWrittenObjects::TPWObj> m_Items;
    +};
    +
     // -----------------------------------------------------------------------------
     const char* TStreamer::StreamableName() const
     {
    @@ -345,20 +370,26 @@
    
     P_id_type TPWrittenObjects::FindObject( TStreamableBase *d )
     {
    +  return Data->Find(TPWObj(((_TCHAR*)(void*)d)+1,0));
    +/*
       unsigned res = Data->Find(TPWObj(((_TCHAR*)(void*)d)+1,0));
       if (res == NPOS)
         return 0;
       else
        return (*Data)[res].Ident;
    +*/
     }
    
     P_id_type TPWrittenObjects::FindVB( TStreamableBase *d )
     {
    +  return Data->Find(TPWObj(d,0));
    +/*
       unsigned res = Data->Find(TPWObj(d,0));
       if (res == NPOS)
         return 0;
       else
       return (*Data)[res].Ident;
    +*/
     }
    
     pstream::~pstream()
    

    It reimplemented TSortedTPWObjObjectArray in terms of a std::set instead of the OWL sorted array.

    Thanks,
    Paul

     
  • Vidar Hasfjord

    Vidar Hasfjord - 2017-03-30

    Consider creating a ticket for this in Feature Requests (or if you deem the bad performance a bug, in Bugs).

     
  • paul

    paul - 2017-03-30
     

Anonymous
Anonymous

Add attachments
Cancel