Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Delay loading plugin files into memory #1091

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Libs/PluginFramework/ctkPluginStorageSQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ ctkPluginStorageSQL::~ctkPluginStorageSQL()
//----------------------------------------------------------------------------
QSqlDatabase ctkPluginStorageSQL::getConnection(bool create) const
{
if (m_connectionNames.hasLocalData() && QSqlDatabase::contains(m_connectionNames.localData()))
if (!m_connectionNames.isEmpty() && QSqlDatabase::contains(m_connectionNames))
{
return QSqlDatabase::database(m_connectionNames.localData());
return QSqlDatabase::database(m_connectionNames);
}

if (!create)
Expand All @@ -84,22 +84,22 @@ QSqlDatabase ctkPluginStorageSQL::getConnection(bool create) const
ctkPluginDatabaseException::DB_NOT_OPEN_ERROR);
}

m_connectionNames.setLocalData(getConnectionName());
m_connectionNames = getConnectionName();

QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE", m_connectionNames.localData());
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE", m_connectionNames);
database.setDatabaseName(getDatabasePath());

if (!database.isValid())
{
close();
throw ctkPluginDatabaseException(QString("Invalid database connection: %1").arg(m_connectionNames.localData()),
throw ctkPluginDatabaseException(QString("Invalid database connection: %1").arg(m_connectionNames),
ctkPluginDatabaseException::DB_CONNECTION_INVALID);
}

if (!database.open())
{
close();
throw ctkPluginDatabaseException(QString("Could not open database connection: %1 (%2)").arg(m_connectionNames.localData()).arg(database.lastError().text()),
throw ctkPluginDatabaseException(QString("Could not open database connection: %1 (%2)").arg(m_connectionNames).arg(database.lastError().text()),
ctkPluginDatabaseException::DB_SQL_ERROR);
}

Expand Down Expand Up @@ -786,7 +786,7 @@ void ctkPluginStorageSQL::close() const
}
else
{
throw ctkPluginDatabaseException(QString("Problem closing database: Invalid connection %1").arg(m_connectionNames.localData()));
throw ctkPluginDatabaseException(QString("Problem closing database: Invalid connection %1").arg(m_connectionNames));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Libs/PluginFramework/ctkPluginStorageSQL_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class ctkPluginStorageSQL : public ctkPluginStorage


QString m_databasePath;
mutable QThreadStorage<QString> m_connectionNames;
mutable QString m_connectionNames;

QMutex m_archivesLock;

Expand Down
24 changes: 12 additions & 12 deletions Libs/PluginFramework/ctkPlugin_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,12 @@ ctkPluginPrivate::ctkPluginPrivate(
QSharedPointer<ctkPluginArchive> pa)
: q_ptr(qq), fwCtx(fw), id(pa->getPluginId()),
location(pa->getPluginLocation().toString()), state(ctkPlugin::INSTALLED),
archive(pa), pluginContext(0), pluginActivator(0), pluginLoader(pa->getLibLocation()),
archive(pa), pluginContext(0), pluginActivator(0),
resolveFailException(0), eagerActivation(false), wasStarted(false)
{
//TODO
//checkCertificates(pa);

// Get library load hints
if (fw->props.contains(ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS))
{
QVariant loadHintsVariant = fw->props[ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS];
if (loadHintsVariant.isValid())
{
QLibrary::LoadHints loadHints = loadHintsVariant.value<QLibrary::LoadHints>();
pluginLoader.setLoadHints(loadHints);
}
}

checkManifestHeaders();

pluginDir = fwCtx->getDataStorage(id);
Expand Down Expand Up @@ -730,6 +719,17 @@ ctkPluginException* ctkPluginPrivate::start0()

ctkPluginException::Type error_type = ctkPluginException::MANIFEST_ERROR;
try {
pluginLoader.setFileName(archive->getLibLocation());
// Get library load hints
if (fwCtx->props.contains(ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS))
{
QVariant loadHintsVariant = fwCtx->props[ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS];
if (loadHintsVariant.isValid())
{
QLibrary::LoadHints loadHints = loadHintsVariant.value<QLibrary::LoadHints>();
pluginLoader.setLoadHints(loadHints);
}
}
pluginLoader.load();
if (!pluginLoader.isLoaded())
{
Expand Down