mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user