[ANNOUNCE] VDR-1.5.12: some "micro" speed improvements

Message ID 476ED734.4010802@gmx.de
State New
Headers

Commit Message

Reinhard Nissl Dec. 23, 2007, 9:46 p.m. UTC
  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

Eddi De Pieri Dec. 27, 2007, 12:59 a.m. UTC | #1
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
  
Clemens Kirchgatterer Dec. 27, 2007, 8:16 a.m. UTC | #2
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
  

Patch

--- ../vdr-1.5.12-orig/epg.h	2006-10-07 15:47:19.000000000 +0200
+++ epg.h	2007-12-23 22:10:31.000000000 +0100
@@ -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);
--- ../vdr-1.5.12-orig/epg.c	2007-06-10 14:52:19.000000000 +0200
+++ epg.c	2007-12-23 22:10:31.000000000 +0100
@@ -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());
+}