Speed up the database by caching the Occurrence hash.

* Change: In Hurricane::SharedPath, the hash for the shared pathes, which
    serves for Map<> storing, were computed "on the fly" at each
    ::getHash() call, and were involving recursive calls of all the
    hashes along the components of the shared path. This is terribly
    slow especially in a design with a deep hierarchy (typical case
    LS180).
      Now, at the cost of one supplemenental unsigned long in each
    SharedPath, it is only computed once in the constructor, and is
    no longer recursive (only access the *first* tail, if any).
      As a consequence, the re-display computation delay becomes
    bearable. But also speed up any transhierarchical walkthough.
This commit is contained in:
Jean-Paul Chaput 2021-10-19 14:48:33 +02:00
parent 180aa52c74
commit d0405d8152
2 changed files with 96 additions and 114 deletions

View File

@ -102,10 +102,11 @@ static char NAME_SEPARATOR = '.';
SharedPath::SharedPath(Instance* headInstance, SharedPath* tailSharedPath)
// ***********************************************************************
: _headInstance(headInstance),
_tailSharedPath(tailSharedPath),
_quarkMap(),
_nextOfInstanceSharedPathMap(NULL)
: _hash(0)
, _headInstance(headInstance)
, _tailSharedPath(tailSharedPath)
, _quarkMap()
, _nextOfInstanceSharedPathMap(NULL)
{
if (!_headInstance)
throw Error("Can't create " + _TName("SharedPath") + " : null head instance");
@ -126,6 +127,7 @@ SharedPath::SharedPath(Instance* headInstance, SharedPath* tailSharedPath)
, getString(_tailSharedPath->getOwnerCell ()).c_str()
);
_hash = (_headInstance->getId() << 1) + ((_tailSharedPath) ? _tailSharedPath->getHash() << 1: 0);
_headInstance->_getSharedPathMap()._insert(this);
cdebug_log(0,0) << "SharedPath::SharedPath() pathHash:" << getHash() << " \"" << this << "\"" << endl;
@ -187,7 +189,8 @@ string SharedPath::getName() const
unsigned long SharedPath::getHash() const
// ***************************************
{ return (_headInstance->getId() << 1) + ((_tailSharedPath) ? _tailSharedPath->getHash() << 1: 0); }
//{ return (_headInstance->getId() << 1) + ((_tailSharedPath) ? _tailSharedPath->getHash() << 1: 0); }
{ return _hash; }
string SharedPath::getJsonString(unsigned long flags) const
// ********************************************************
@ -245,6 +248,10 @@ void SharedPath::setNameSeparator(char nameSeparator)
NAME_SEPARATOR = nameSeparator;
}
std::string SharedPath::_getTypeName () const
// ******************************************
{ return _TName("SharedPath"); }
string SharedPath::_getString() const
// **********************************
{

View File

@ -1,25 +1,35 @@
// ****************************************************************************************************
// File: ./hurricane/SharedPath.h
// Authors: R. Escassut
// -*- C++ -*-
//
// Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
//
// This file is part of Hurricane.
//
// Hurricane is free software: you can redistribute it and/or modify it under the terms of the GNU
// Lesser General Public License as published by the Free Software Foundation, either version 3 of the
// Hurricane is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// Hurricane is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
// Hurricane is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
// TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
// General Public License for more details.
//
// You should have received a copy of the Lesser GNU General Public License along with Hurricane. If
// not, see <http://www.gnu.org/licenses/>.
// ****************************************************************************************************
// You should have received a copy of the Lesser GNU General Public
// License along with Hurricane. If not, see
// <http://www.gnu.org/licenses/>.
//
// +-----------------------------------------------------------------+
// | H U R R I C A N E |
// | V L S I B a c k e n d D a t a - B a s e |
// | |
// | Authors : Remy Escassut |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./hurricane/RoutingPad.h" |
// +-----------------------------------------------------------------+
#ifndef HURRICANE_SHARED_PATH
#define HURRICANE_SHARED_PATH
#pragma once
#include "hurricane/Instances.h"
#include "hurricane/SharedPathes.h"
#include "hurricane/Quark.h"
@ -28,112 +38,77 @@
namespace Hurricane {
class Cell;
class Entity;
class Cell;
class Entity;
// -------------------------------------------------------------------
// Class : "SharedPath".
// ****************************************************************************************************
// SharedPath declaration
// ****************************************************************************************************
class SharedPath {
// *************
// Types
// *****
public: class QuarkMap : public IntrusiveMap<const Entity*, Quark> {
// ***************************************************************
public: typedef IntrusiveMap<const Entity*, Quark> Inherit;
public: QuarkMap();
public: virtual const Entity* _getKey(Quark* quark) const;
public: virtual unsigned _getHashValue(const Entity* entity) const;
public: virtual Quark* _getNextElement(Quark* quark) const;
public: virtual void _setNextElement(Quark* quark, Quark* nextQuark) const;
class SharedPath {
public:
class QuarkMap : public IntrusiveMap<const Entity*, Quark> {
public:
typedef IntrusiveMap<const Entity*, Quark> Inherit;
public:
QuarkMap ();
virtual const Entity* _getKey ( Quark* ) const;
virtual unsigned _getHashValue ( const Entity* ) const;
virtual Quark* _getNextElement ( Quark* ) const;
virtual void _setNextElement ( Quark* , Quark* nextQuark ) const;
};
// Attributes
// **********
public:
SharedPath ( Instance* headInstance, SharedPath* tailSharedPath = NULL );
~SharedPath ();
private:
SharedPath ( const SharedPath& ) = delete;
SharedPath& operator= ( const SharedPath& ) = delete;
public:
static char getNameSeparator ();
static void setNameSeparator ( char nameSeparator );
public:
unsigned long getHash () const;
inline Instance* getHeadInstance () const;
inline SharedPath* getTailSharedPath () const;
SharedPath* getHeadSharedPath () const;
Instance* getTailInstance () const;
std::string getName () const;
std::string getJsonString ( unsigned long flags ) const;
Cell* getOwnerCell () const;
Cell* getMasterCell () const;
Instances getInstances () const;
Transformation getTransformation ( const Transformation& transformation=Transformation() ) const;
public:
std::string _getTypeName () const;
std::string _getString () const;
Record* _getRecord () const;
inline Quark* _getQuark (const Entity* entity ) const;
inline Quarks _getQuarks () const;
inline QuarkMap& _getQuarkMap ();
inline SharedPath* _getNextOfInstanceSharedPathMap () const;
inline void _setNextOfInstanceSharedPathMap ( SharedPath* sharedPath );
private:
// Attributes.
unsigned long _hash;
Instance* _headInstance;
SharedPath* _tailSharedPath;
QuarkMap _quarkMap;
SharedPath* _nextOfInstanceSharedPathMap;
};
private: Instance* _headInstance;
private: SharedPath* _tailSharedPath;
private: QuarkMap _quarkMap;
private: SharedPath* _nextOfInstanceSharedPathMap;
// Constructors
// ************
public: SharedPath(Instance* headInstance, SharedPath* tailSharedPath = NULL);
private: SharedPath(const SharedPath& sharedPath);
// not implemented to forbid copy construction
// Destructor
// **********
public: ~SharedPath();
// Operators
// *********
private: SharedPath& operator=(const SharedPath& sharedPath);
// not implemented to forbid assignment
// Accessors
// *********
public: static char getNameSeparator();
public: unsigned long getHash() const;
public: Instance* getHeadInstance() const {return _headInstance;};
public: SharedPath* getTailSharedPath() const {return _tailSharedPath;};
public: SharedPath* getHeadSharedPath() const;
public: Instance* getTailInstance() const;
public: string getName() const;
public: string getJsonString(unsigned long flags) const;
public: Cell* getOwnerCell() const;
public: Cell* getMasterCell() const;
public: Instances getInstances() const;
public: Transformation getTransformation(const Transformation& transformation = Transformation()) const;
// Updators
// ********
public: static void setNameSeparator(char nameSeparator);
// Accessors
// *********
public: string _getTypeName() const { return _TName("SharedPath"); };
public: string _getString() const;
public: Record* _getRecord() const;
public: Quark* _getQuark(const Entity* entity) const {return _quarkMap.getElement(entity);};
public: Quarks _getQuarks() const {return _quarkMap.getElements();};
public: QuarkMap& _getQuarkMap() {return _quarkMap;};
public: SharedPath* _getNextOfInstanceSharedPathMap() const {return _nextOfInstanceSharedPathMap;};
public: void _setNextOfInstanceSharedPathMap(SharedPath* sharedPath) {_nextOfInstanceSharedPathMap = sharedPath;};
};
inline Instance* SharedPath::getHeadInstance () const { return _headInstance; }
inline SharedPath* SharedPath::getTailSharedPath () const { return _tailSharedPath; }
inline Quark* SharedPath::_getQuark (const Entity* entity ) const { return _quarkMap.getElement(entity); }
inline Quarks SharedPath::_getQuarks () const { return _quarkMap.getElements(); }
inline SharedPath::QuarkMap& SharedPath::_getQuarkMap () { return _quarkMap; }
inline SharedPath* SharedPath::_getNextOfInstanceSharedPathMap () const { return _nextOfInstanceSharedPathMap; }
inline void SharedPath::_setNextOfInstanceSharedPathMap ( SharedPath* sharedPath ) { _nextOfInstanceSharedPathMap = sharedPath; }
} // End of Hurricane namespace.
} // Hurricane namespace.
INSPECTOR_P_SUPPORT(Hurricane::SharedPath);
#endif // HURRICANE_SHARED_PATH
// ****************************************************************************************************
// Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
// ****************************************************************************************************