mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-26 15:47:19 +02:00
Performance
- Added locally cached configuration for urgency coefficients, which effectively relocates expensive loop-invariants for the 'next' report.
This commit is contained in:
parent
2668b04901
commit
0c0f767688
3 changed files with 98 additions and 44 deletions
|
@ -140,6 +140,10 @@ int Context::initialize (int argc, const char** argv)
|
||||||
// Apply rc overrides to Context::config, capturing raw args for later use.
|
// Apply rc overrides to Context::config, capturing raw args for later use.
|
||||||
a3.apply_overrides ();
|
a3.apply_overrides ();
|
||||||
|
|
||||||
|
// Now that the final RC is in place, initialize the urgency coefficients
|
||||||
|
// to speed the 'next' report.
|
||||||
|
initializeUrgencyCoefficients ();
|
||||||
|
|
||||||
// Initialize the color rules, if necessary.
|
// Initialize the color rules, if necessary.
|
||||||
if (color ())
|
if (color ())
|
||||||
initializeColorRules ();
|
initializeColorRules ();
|
||||||
|
|
135
src/Task.cpp
135
src/Task.cpp
|
@ -27,9 +27,9 @@
|
||||||
|
|
||||||
#define L10N // Localization complete.
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
//#include <iostream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Nibbler.h>
|
#include <Nibbler.h>
|
||||||
|
@ -47,6 +47,52 @@
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
||||||
|
static const float epsilon = 0.000001;
|
||||||
|
|
||||||
|
static std::map <std::string, float> coefficients;
|
||||||
|
float urgencyPriorityCoefficient = 0.0;
|
||||||
|
float urgencyProjectCoefficient = 0.0;
|
||||||
|
float urgencyActiveCoefficient = 0.0;
|
||||||
|
float urgencyWaitingCoefficient = 0.0;
|
||||||
|
float urgencyBlockedCoefficient = 0.0;
|
||||||
|
float urgencyAnnotationsCoefficient = 0.0;
|
||||||
|
float urgencyTagsCoefficient = 0.0;
|
||||||
|
float urgencyNextCoefficient = 0.0;
|
||||||
|
float urgencyDueCoefficient = 0.0;
|
||||||
|
float urgencyBlockingCoefficient = 0.0;
|
||||||
|
float urgencyAgeCoefficient = 0.0;
|
||||||
|
|
||||||
|
static const std::string dummy ("");
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Non-method.
|
||||||
|
//
|
||||||
|
// This is essentialy a cache of float values to save iteration and hash lookup
|
||||||
|
// in the whole config at time of Task::urgency_C.
|
||||||
|
void initializeUrgencyCoefficients ()
|
||||||
|
{
|
||||||
|
urgencyPriorityCoefficient = context.config.getReal ("urgency.priority.coefficient");
|
||||||
|
urgencyProjectCoefficient = context.config.getReal ("urgency.project.coefficient");
|
||||||
|
urgencyActiveCoefficient = context.config.getReal ("urgency.active.coefficient");
|
||||||
|
urgencyWaitingCoefficient = context.config.getReal ("urgency.waiting.coefficient");
|
||||||
|
urgencyBlockedCoefficient = context.config.getReal ("urgency.blocked.coefficient");
|
||||||
|
urgencyAnnotationsCoefficient = context.config.getReal ("urgency.annotations.coefficient");
|
||||||
|
urgencyTagsCoefficient = context.config.getReal ("urgency.tags.coefficient");
|
||||||
|
urgencyNextCoefficient = context.config.getReal ("urgency.next.coefficient");
|
||||||
|
urgencyDueCoefficient = context.config.getReal ("urgency.due.coefficient");
|
||||||
|
urgencyBlockingCoefficient = context.config.getReal ("urgency.blocking.coefficient");
|
||||||
|
urgencyAgeCoefficient = context.config.getReal ("urgency.age.coefficient");
|
||||||
|
|
||||||
|
// Tag- and project-specific coefficients.
|
||||||
|
std::vector <std::string> all;
|
||||||
|
context.config.all (all);
|
||||||
|
|
||||||
|
std::vector <std::string>::iterator var;
|
||||||
|
for (var = all.begin (); var != all.end (); ++var)
|
||||||
|
if (var->substr (0, 13) == "urgency.user.")
|
||||||
|
coefficients[*var] = context.config.getReal (*var);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Task::Task ()
|
Task::Task ()
|
||||||
: id (0)
|
: id (0)
|
||||||
|
@ -1249,61 +1295,62 @@ int Task::determineVersion (const std::string& line)
|
||||||
float Task::urgency_c () const
|
float Task::urgency_c () const
|
||||||
{
|
{
|
||||||
float value = 0.0;
|
float value = 0.0;
|
||||||
value += urgency_priority () * context.config.getReal ("urgency.priority.coefficient");
|
value += fabsf (urgencyPriorityCoefficient) > epsilon ? (urgency_priority () * urgencyPriorityCoefficient) : 0.0;
|
||||||
value += urgency_project () * context.config.getReal ("urgency.project.coefficient");
|
value += fabsf (urgencyProjectCoefficient) > epsilon ? (urgency_project () * urgencyProjectCoefficient) : 0.0;
|
||||||
value += urgency_active () * context.config.getReal ("urgency.active.coefficient");
|
value += fabsf (urgencyActiveCoefficient) > epsilon ? (urgency_active () * urgencyActiveCoefficient) : 0.0;
|
||||||
value += urgency_waiting () * context.config.getReal ("urgency.waiting.coefficient");
|
value += fabsf (urgencyWaitingCoefficient) > epsilon ? (urgency_waiting () * urgencyWaitingCoefficient) : 0.0;
|
||||||
value += urgency_blocked () * context.config.getReal ("urgency.blocked.coefficient");
|
value += fabsf (urgencyBlockedCoefficient) > epsilon ? (urgency_blocked () * urgencyBlockedCoefficient) : 0.0;
|
||||||
value += urgency_annotations () * context.config.getReal ("urgency.annotations.coefficient");
|
value += fabsf (urgencyAnnotationsCoefficient) > epsilon ? (urgency_annotations () * urgencyAnnotationsCoefficient) : 0.0;
|
||||||
value += urgency_tags () * context.config.getReal ("urgency.tags.coefficient");
|
value += fabsf (urgencyTagsCoefficient) > epsilon ? (urgency_tags () * urgencyTagsCoefficient) : 0.0;
|
||||||
value += urgency_next () * context.config.getReal ("urgency.next.coefficient");
|
value += fabsf (urgencyNextCoefficient) > epsilon ? (urgency_next () * urgencyNextCoefficient) : 0.0;
|
||||||
value += urgency_due () * context.config.getReal ("urgency.due.coefficient");
|
value += fabsf (urgencyDueCoefficient) > epsilon ? (urgency_due () * urgencyDueCoefficient) : 0.0;
|
||||||
value += urgency_blocking () * context.config.getReal ("urgency.blocking.coefficient");
|
value += fabsf (urgencyBlockingCoefficient) > epsilon ? (urgency_blocking () * urgencyBlockingCoefficient) : 0.0;
|
||||||
value += urgency_age () * context.config.getReal ("urgency.age.coefficient");
|
value += fabsf (urgencyAgeCoefficient) > epsilon ? (urgency_age () * urgencyAgeCoefficient) : 0.0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
// Very useful for debugging urgency problems.
|
||||||
std::cout << "# Urgency for " << id << ":\n"
|
std::cout << "# Urgency for " << id << ":\n"
|
||||||
<< "# pri " << (urgency_priority () * context.config.getReal ("urgency.priority.coefficient"))
|
<< "# pri " << (urgency_priority () * urgencyPriorityCoefficient)
|
||||||
<< "# pro " << (urgency_project () * context.config.getReal ("urgency.project.coefficient"))
|
<< "# pro " << (urgency_project () * urgencyProjectCoefficient)
|
||||||
<< "# act " << (urgency_active () * context.config.getReal ("urgency.active.coefficient"))
|
<< "# act " << (urgency_active () * urgencyActiveCoefficient)
|
||||||
<< "# wai " << (urgency_waiting () * context.config.getReal ("urgency.waiting.coefficient"))
|
<< "# wai " << (urgency_waiting () * urgencyWaitingCoefficient)
|
||||||
<< "# blk " << (urgency_blocked () * context.config.getReal ("urgency.blocked.coefficient"))
|
<< "# blk " << (urgency_blocked () * urgencyBlockedCoefficient)
|
||||||
<< "# ann " << (urgency_annotations () * context.config.getReal ("urgency.annotations.coefficient"))
|
<< "# ann " << (urgency_annotations () * urgencyAnnotationsCoefficient)
|
||||||
<< "# tag " << (urgency_tags () * context.config.getReal ("urgency.tags.coefficient"))
|
<< "# tag " << (urgency_tags () * urgencyTagsCoefficient)
|
||||||
<< "# nex " << (urgency_next () * context.config.getReal ("urgency.next.coefficient"))
|
<< "# nex " << (urgency_next () * urgencyNextCoefficient)
|
||||||
<< "# due " << (urgency_due () * context.config.getReal ("urgency.due.coefficient"))
|
<< "# due " << (urgency_due () * urgencyDueCoefficient)
|
||||||
<< "# bkg " << (urgency_blocking () * context.config.getReal ("urgency.blocking.coefficient"))
|
<< "# bkg " << (urgency_blocking () * urgencyBlockingCoefficient)
|
||||||
<< "# age " << (urgency_age () * context.config.getReal ("urgency.age.coefficient"));
|
<< "# age " << (urgency_age () * urgencyAgeCoefficient);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Tag- and project-specific coefficients.
|
// Tag- and project-specific coefficients.
|
||||||
std::vector <std::string> all;
|
std::map <std::string, float>::iterator var;
|
||||||
context.config.all (all);
|
for (var = coefficients.begin (); var != coefficients.end (); ++var)
|
||||||
|
|
||||||
std::vector <std::string>::iterator var;
|
|
||||||
for (var = all.begin (); var != all.end (); ++var)
|
|
||||||
{
|
{
|
||||||
if (var->substr (0, 13) == "urgency.user.")
|
if (var->second > epsilon)
|
||||||
{
|
{
|
||||||
// urgency.user.project.<project>.coefficient
|
if (var->first.substr (0, 13) == "urgency.user.")
|
||||||
std::string::size_type end = std::string::npos;
|
|
||||||
if (var->substr (13, 8) == "project." &&
|
|
||||||
(end = var->find (".coefficient")) != std::string::npos)
|
|
||||||
{
|
{
|
||||||
std::string project = var->substr (21, end - 21);
|
// urgency.user.project.<project>.coefficient
|
||||||
|
std::string::size_type end = std::string::npos;
|
||||||
|
if (var->first.substr (13, 8) == "project." &&
|
||||||
|
(end = var->first.find (".coefficient")) != std::string::npos)
|
||||||
|
{
|
||||||
|
std::string project = var->first.substr (21, end - 21);
|
||||||
|
|
||||||
if (get ("project").find (project) == 0)
|
if (get ("project").find (project) == 0)
|
||||||
value += context.config.getReal (*var);
|
value += var->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// urgency.user.tag.<tag>.coefficient
|
// urgency.user.tag.<tag>.coefficient
|
||||||
if (var->substr (13, 4) == "tag." &&
|
if (var->first.substr (13, 4) == "tag." &&
|
||||||
(end = var->find (".coefficient")) != std::string::npos)
|
(end = var->first.find (".coefficient")) != std::string::npos)
|
||||||
{
|
{
|
||||||
std::string tag = var->substr (17, end - 17);
|
std::string tag = var->first.substr (17, end - 17);
|
||||||
|
|
||||||
if (hasTag (tag))
|
if (hasTag (tag))
|
||||||
value += context.config.getReal (*var);
|
value += var->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
void initializeUrgencyCoefficients ();
|
||||||
|
|
||||||
class Task : public std::map <std::string, std::string>
|
class Task : public std::map <std::string, std::string>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue