[ANNOUNCE] VDR-1.5.12: some "micro" speed improvements
Commit Message
Hi,
the attached patches speed up starting and stopping VDR on slow machines
with huge channels.conf files, by avoiding some n / 2 * (n + 1) loops.
Please test them and report bugs here.
Bye.
Comments
Il giorno dom, 23/12/2007 alle 22.46 +0100, Reinhard Nissl ha scritto:
> Hi,
>
> the attached patches speed up starting and stopping VDR on slow machines
> with huge channels.conf files, by avoiding some n / 2 * (n + 1) loops.
>
> Please test them and report bugs here.
Hi Reinhard,
Your patches seems to be good!
Since often vdr run on not so recent pcs, I think optimization is good!
I haven't tested them yet, but I hope will be merged into the mainline!
Regards,
Eddi
Reinhard Nissl <rnissl@gmx.de> wrote:
> the attached patches speed up starting and stopping VDR on slow
> machines with huge channels.conf files, by avoiding some n / 2 * (n +
> 1) loops.
>
> Please test them and report bugs here.
i have your first patch (with the hashzise bug) running for a week now
without problems. i cannot provide numbers but i think it halps on one
of my vdr clients a 300mhz geode.
thx & best regards ...
clemens
@@ -164,11 +164,15 @@ class cSchedules : public cList<cSchedul
friend class cSchedulesLock;
private:
cRwLock rwlock;
+ cHash<cSchedule> schedulesHash;
static cSchedules schedules;
static const char *epgDataFileName;
static time_t lastCleanup;
static time_t lastDump;
static time_t modified;
+ void HashSchedule(cSchedule *Schedule);
+ void UnhashSchedule(cSchedule *Schedule);
+ static unsigned int HashKey(tChannelID ChannelID);
public:
static void SetEpgDataFileName(const char *FileName);
static const cSchedules *Schedules(cSchedulesLock &SchedulesLock);
@@ -1045,6 +1045,7 @@ cSchedule *cSchedules::AddSchedule(tChan
if (!p) {
p = new cSchedule(ChannelID);
Add(p);
+ HashSchedule(p);
cChannel *channel = Channels.GetByChannelID(ChannelID);
if (channel)
channel->schedule = p;
@@ -1055,10 +1056,14 @@ cSchedule *cSchedules::AddSchedule(tChan
const cSchedule *cSchedules::GetSchedule(tChannelID ChannelID) const
{
ChannelID.ClrRid();
- for (cSchedule *p = First(); p; p = Next(p)) {
- if (p->ChannelID() == ChannelID)
- return p;
- }
+ cList<cHashObject> *list = schedulesHash.GetList(HashKey(ChannelID));
+ if (list) {
+ for (cHashObject *hobj = list->First(); hobj; hobj = list->Next(hobj)) {
+ cSchedule *p = (cSchedule *)hobj->Object();
+ if (p->ChannelID() == ChannelID)
+ return p;
+ }
+ }
return NULL;
}
@@ -1074,7 +1079,23 @@ const cSchedule *cSchedules::GetSchedule
if (Channel->schedule == &DummySchedule && AddIfMissing) {
cSchedule *Schedule = new cSchedule(Channel->GetChannelID());
((cSchedules *)this)->Add(Schedule);
+ ((cSchedules *)this)->HashSchedule(Schedule);
Channel->schedule = Schedule;
}
return Channel->schedule != &DummySchedule? Channel->schedule : NULL;
}
+
+void cSchedules::HashSchedule(cSchedule *Schedule)
+{
+ schedulesHash.Add(Schedule, HashKey(Schedule->ChannelID().ClrRid()));
+}
+
+void cSchedules::UnhashSchedule(cSchedule *Schedule)
+{
+ schedulesHash.Del(Schedule, HashKey(Schedule->ChannelID().ClrRid()));
+}
+
+unsigned int cSchedules::HashKey(tChannelID ChannelID)
+{
+ return (unsigned int)((ChannelID.Nid() << 16 | ChannelID.Source()) ^ (ChannelID.Tid() << 16 | ChannelID.Sid()) ^ ChannelID.Rid());
+}