perf: faster shutdown (#2193)

* perf: don't update queue positions during shutdown

When a torrent is being removed, we try to update the queue positions of
the other torrents. But it's (slightly) expensive and is irrelevant when
the session is closing, so skip it in that case.

* perf: torrentLoadResume shouldn't touch tor->dirty

Loading torrent settings from disk does call a lot of tr_torrentSetFoo()
functions, but since these are the saved settings, they shouldnt' affect
the torrent's 'is dirty' flag.
This commit is contained in:
Charles Kerr
2021-11-18 12:19:55 -06:00
committed by GitHub
parent 0eca3b3c6c
commit b3e4fc64c5
4 changed files with 25 additions and 10 deletions

View File

@@ -1838,7 +1838,7 @@ static void sessionCloseImplWaitForIdleUdp(evutil_socket_t fd, short what, void*
static void sessionCloseImplStart(tr_session* session)
{
session->isClosing = true;
session->is_closing_ = true;
free_incoming_peer_port(session);

View File

@@ -135,6 +135,11 @@ struct CaseInsensitiveStringCompare // case-insensitive string compare
struct tr_session
{
public:
bool isClosing() const
{
return is_closing_;
}
// download dir
std::string const& downloadDir() const
@@ -261,7 +266,7 @@ public:
bool isUTPEnabled;
bool isLPDEnabled;
bool isPrefetchEnabled;
bool isClosing;
bool is_closing_ = false;
bool isClosed;
bool isRatioLimited;
bool isIdleLimited;

View File

@@ -887,8 +887,14 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
torrentInitFromInfo(tor);
// tr_torrentLoadResume() calls a lot of tr_torrentSetFoo() methods
// that set things as dirty, but... these settings being loaded are
// the same ones that would be saved back again, so don't let them
// affect the 'is dirty' flag.
auto const was_dirty = tor->isDirty;
bool didRenameResumeFileToHashOnlyName = false;
auto const loaded = tr_torrentLoadResume(tor, ~(uint64_t)0, ctor, &didRenameResumeFileToHashOnlyName);
tor->isDirty = was_dirty;
if (didRenameResumeFileToHashOnlyName)
{
@@ -1517,17 +1523,21 @@ static void freeTorrent(tr_torrent* tor)
tr_sessionRemoveTorrent(session, tor);
/* resequence the queue positions */
for (auto* t : session->torrents)
if (!session->isClosing())
{
if (t->queuePosition > tor->queuePosition)
// "so you die, captain, and we all move up in rank."
// resequence the queue positions
for (auto* t : session->torrents)
{
t->queuePosition--;
t->anyDate = now;
if (t->queuePosition > tor->queuePosition)
{
t->queuePosition--;
t->anyDate = now;
}
}
}
TR_ASSERT(queueIsSequenced(session));
TR_ASSERT(queueIsSequenced(session));
}
delete tor->bandwidth;

View File

@@ -340,7 +340,7 @@ static struct tr_web_task* tr_webRunImpl(
{
struct tr_web_task* task = nullptr;
if (!session->isClosing)
if (!session->isClosing())
{
if (session->web == nullptr)
{