[ROOT] TGTextView optimizing

From: Maxim Nikulin (nikulin@gorodok.net)
Date: Wed Sep 01 2004 - 13:21:52 MEST


Hi,

I use TGTextView widgets in my monitor program. Several thousands calls 
of the AddLine() method make the program extremely slow. Using the 
callgrind program I found that the AddLine() is most expensive in my 
case because of Layout() invocations.

I suggest add methods AddLineFast() and Update(). Together they do the 
same work to AddLine(), but it becomes possible to invoke AddLineFast() 
many times and call the slow Update() method only once.

I prepare a patch for the 4.00.08b version, it's in the attachment. To 
apply it type
patch -p1 < TGTextView_optimize.patch
in the root/gui directory.

-- 
Max


diff -Naur --exclude '*.o' --exclude 'G_*' --exclude '*~' gui.orig/inc/TGTextView.h gui/inc/TGTextView.h
--- gui.orig/inc/TGTextView.h	2004-09-01 17:30:07.110372652 +0700
+++ gui/inc/TGTextView.h	2004-09-01 17:31:38.282760265 +0700
@@ -98,6 +98,8 @@
    virtual void SetText(TGText *text);
    virtual void AddText(TGText *text);
    virtual void AddLine(const char *string);
+   virtual void AddLineFast(const char *string);
+   virtual void Update();
    TGText      *GetText() const { return fText; }
 
    virtual void DataChanged() { Emit("DataChanged()"); }  //*SIGNAL*
diff -Naur --exclude '*.o' --exclude 'G_*' --exclude '*~' gui.orig/src/TGTextView.cxx gui/src/TGTextView.cxx
--- gui.orig/src/TGTextView.cxx	2004-09-01 17:30:07.434324342 +0700
+++ gui/src/TGTextView.cxx	2004-09-01 17:59:00.471639063 +0700
@@ -148,14 +148,32 @@
 {
    // Add a line of text to the view widget.
 
+   AddLineFast(string);
+   Update();
+}
+
+//______________________________________________________________________________
+void TGTextView::AddLineFast(const char *string)
+{
+   // Add a line of text to the view widget.
+   // Fast version. Use it if you are going to add
+   //  several lines, than call Update().
+
    TGLongPosition pos;
    pos.fX = 0;
    pos.fY = fText->RowCount();
    fText->InsText(pos, string);
+}
+
+//______________________________________________________________________________
+void TGTextView::Update ()
+{
+   // Call this function after AddLineFast()
    Layout();
    DrawRegion(0, 0, fCanvas->GetWidth(), fCanvas->GetHeight());
 }
 
+
 //______________________________________________________________________________
 Long_t TGTextView::ReturnLongestLineWidth()
 {



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET