Subject: Re: [sup-devel] Scrolling (with patches)

From: Rich Lane <[email-masked]>
Date: Thu, 30 Dec 2010 19:10:06 -0500

Yeah, I've noticed how slow method_missing is and that's also a problem
with our use of Singleton in the codebase. Here we might as well hoist
the conditional out of the method definition.
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Tero Tilus <[email-masked]>
Date: Fri, 31 Dec 2010 02:34:09 +0200

Rich Lane, 2010-12-31 02:10:
> Yeah, I've noticed how slow method_missing is and that's also a
> problem with our use of Singleton in the codebase.

I think we could have Singleton.method_missing actually create the
methods as they are called.

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Tero Tilus <[email-masked]>
Date: Fri, 31 Dec 2010 05:18:29 +0200

Tero Tilus, 2010-12-31 03:44:
> From words to deeds.  ;)

...to first fix.  Private methods (at least Index.sync_message) are
being called on singletons and looks like they are expected to work.

---

From: Rich Lane <[email-masked]>
Date: Tue, 18 Jan 2011 22:13:38 -0500

Applied to master.

---

From: Tero Tilus <[email-masked]>
Date: Fri, 31 Dec 2010 03:44:36 +0200

---

From: Rich Lane <[email-masked]>
Date: Tue, 18 Jan 2011 22:15:42 -0500

Applied to master.

---

From: Tero Tilus <[email-masked]>
Date: Fri, 31 Dec 2010 01:35:56 +0200

Jonas H. reported about slow horizontal scrolling on talk.
http://rubyforge.org/pipermail/sup-talk/2010-December/004400.html

I looked into it and found out that scrolling is pretty much fully
dependant on Buffer#write and main cpu hogs within it are
String#display_length (uses String#scan when on 1.8) and
Ncurses::WINDOW#method_missing (wide/normal dispatching).

Caching String#display_length cuts down String#scan calls by ~30%.
That and hardwiring Ncurses::WINDOW#mvaddstr and #attrset cut average
Buffer#write call to half of what it was.

Also having configurable COL_JUMP would help people who need to scroll
horizontally a lot.  Included in the sup patch.

Perceivable difference of these modifications is very small, at least
to me.  Please have a look if these patches (one of them against sup
and another against ncursesw.rb in ncursesw gem) make any sense.

====
--- /usr/lib/ruby/gems/1.8/gems/ncursesw-1.2.4.2/lib/ncursesw.rb        2010-12-
31 00:37:31.000000000 +0200
+++ lib/ncurses.rb        2010-12-30 23:50:26.000000000 +0200
@@ -59,6 +58,29 @@
   module Destroy_checker; def destroyed?; @destroyed; end; end
   class WINDOW
     include Destroy_checker
+
+    @@mvwaddstr = Ncurses.respond_to? "mvwaddstr"
+    # This would be handled by #method_missing below, but for
+    # performance reasons it is extracted here.  #mvaddstr is the beef
+    # of Redwood::Buffer#write which does all the drawing.
+    def mvaddstr(*args)
+      if @@mvwaddstr
+        Ncurses.mvwaddstr(*args)
+      else
+        Ncurses.mvaddstr(*args)
+      end
+    end
+
+    @@wattrset = Ncurses.respond_to? "wattrset"
+    # See #mvaddstr abowe.
+    def attrset(*args)
+      if @@wattrset
+        Ncurses.wattrset(*args)
+      else
+        Ncurses.attrset(*args)
+      end
+    end
+
     def method_missing(name, *args)
       name = name.to_s
       if (name[0,2] == "mv")
====