Commit d0405d81 authored by Jean-Paul Chaput's avatar Jean-Paul Chaput
Browse files

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.
parent 180aa52c
......@@ -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
// **********************************
{
......
// ****************************************************************************************************
// 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/>.
// ****************************************************************************************************
#ifndef HURRICANE_SHARED_PATH
#define HURRICANE_SHARED_PATH
// 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" |
// +-----------------------------------------------------------------+
#pragma once
#include "hurricane/Instances.h"
#include "hurricane/SharedPathes.h"
#include "hurricane/Quark.h"
......@@ -28,112 +38,77 @@
namespace Hurricane {
class Cell;
class Entity;
// ****************************************************************************************************
// SharedPath declaration
// ****************************************************************************************************
class SharedPath {
// *************
// Types
// *****
class Cell;
class Entity;
public: class QuarkMap : public IntrusiveMap<const Entity*, Quark> {
// ***************************************************************
public: typedef IntrusiveMap<const Entity*, Quark> Inherit;
public: QuarkMap();
// -------------------------------------------------------------------
// Class : "SharedPath".
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
// **********
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;};
};
} // End of Hurricane namespace.
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;
};
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; }
} // Hurricane namespace.
INSPECTOR_P_SUPPORT(Hurricane::SharedPath);
#endif // HURRICANE_SHARED_PATH
// ****************************************************************************************************
// Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
// ****************************************************************************************************
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment