Skip to content

Commit

Permalink
perf: Optimize call to get backend server port.
Browse files Browse the repository at this point in the history
When building the "Videos" dialog, the calls to
gCoreContext->GetBackendServerPort consume 3% of the total time to
build the window. Given that this value will probably never change
once it is set, cache the result to save time.
  • Loading branch information
linuxdude42 committed Sep 11, 2021
1 parent d1656f3 commit 2f8749b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
14 changes: 13 additions & 1 deletion mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -1090,12 +1090,24 @@ int MythCoreContext::GetBackendServerPort(void)
return GetBackendServerPort(d->m_localHostname);
}

QHash<QString,int> MythCoreContext::s_serverPortCache;

void MythCoreContext::ClearBackendServerPortCache()
{
s_serverPortCache.clear();
}

/**
* Returns the backend "hosts"'s control port
*/
int MythCoreContext::GetBackendServerPort(const QString &host)
{
return GetNumSettingOnHost("BackendServerPort", host, 6543);
int port = s_serverPortCache.value(host, -1);
if (port != -1)
return port;
port = GetNumSettingOnHost("BackendServerPort", host, 6543);
s_serverPortCache[host] = port;
return port;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythbase/mythcorecontext.h
Expand Up @@ -202,8 +202,10 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
int GetMasterServerStatusPort(void);
int GetBackendServerPort(void);
int GetBackendServerPort(const QString &host);
static void ClearBackendServerPortCache();
int GetBackendStatusPort(void);
int GetBackendStatusPort(const QString &host);
static QHash<QString,int> s_serverPortCache;

bool GetScopeForAddress(QHostAddress &addr) const;
void SetScopeForAddress(const QHostAddress &addr);
Expand Down
1 change: 1 addition & 0 deletions mythtv/programs/mythfrontend/videodlg.cpp
Expand Up @@ -864,6 +864,7 @@ VideoDialog::VideoDialog(MythScreenStack *lparent, const QString& lname,
ParentalLevel::plLowest)));

StorageGroup::ClearGroupToUseCache();
MythCoreContext::ClearBackendServerPortCache();
}

VideoDialog::~VideoDialog()
Expand Down
8 changes: 7 additions & 1 deletion mythtv/programs/mythtv-setup/backendsettings.cpp
Expand Up @@ -144,14 +144,20 @@ class IpAddressSettings : public HostCheckBoxSetting
};


void BackendSettings::LocalServerPortChanged ()
{
MythCoreContext::ClearBackendServerPortCache();
}

static HostTextEditSetting *LocalServerPort()
HostTextEditSetting *BackendSettings::LocalServerPort() const
{
auto *gc = new HostTextEditSetting("BackendServerPort");
gc->setLabel(QObject::tr("Port"));
gc->setValue("6543");
gc->setHelpText(QObject::tr("Unless you've got good reason, don't "
"change this."));
connect(gc, &StandardSetting::ChangeSaved,
this, &BackendSettings::LocalServerPortChanged);
return gc;
};

Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythtv-setup/backendsettings.h
Expand Up @@ -14,6 +14,8 @@ class BackendSettings : public GroupSetting
~BackendSettings() override;

private:
HostTextEditSetting *LocalServerPort(void) const;

TransMythUICheckBoxSetting *m_isMasterBackend {nullptr};
HostTextEditSetting *m_localServerPort {nullptr};
HostComboBoxSetting *m_backendServerAddr {nullptr};
Expand All @@ -29,7 +31,7 @@ class BackendSettings : public GroupSetting
private slots:
void masterBackendChanged(void);
void listenChanged(void);
static void LocalServerPortChanged(void);
};

#endif

0 comments on commit 2f8749b

Please sign in to comment.