Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Tero Tilus <tero@tilus.net>
To: Sup developers <sup-devel@rubyforge.org>
Subject: [sup-devel] Scrolling (with patches)
Date: Fri, 31 Dec 2010 01:35:56 +0200	[thread overview]
Message-ID: <1293750761-sup-3852@tilus.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1947 bytes --]

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")
====

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/

[-- Attachment #2: 0002-Performance-and-configurability-of-horizontal-scroll.patch --]
[-- Type: application/octet-stream, Size: 2673 bytes --]

From b0cc0af26534ef2848f9871797c411ca01bba0e0 Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Fri, 31 Dec 2010 00:48:03 +0200
Subject: [PATCH] Performance and configurability of horizontal scrolling

---
 lib/sup.rb                   |    3 ++-
 lib/sup/colormap.rb          |    2 ++
 lib/sup/modes/scroll-mode.rb |   12 +++++++-----
 lib/sup/util.rb              |    3 ++-
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lib/sup.rb b/lib/sup.rb
index f4e4601..14e471a 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -283,7 +283,8 @@ EOS
         :sent_source => "sup://sent",
         :poll_interval => 300,
         :wrap_width => 0,
-        :slip_rows => 0
+        :slip_rows => 0,
+        :col_jump => 2
       }
       begin
         Redwood::save_yaml_obj config, filename
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
index 8402add..a3c4309 100644
--- a/lib/sup/colormap.rb
+++ b/lib/sup/colormap.rb
@@ -220,6 +220,8 @@ class Colormap
     Colormap.new unless @@instance
     @@instance.send meth, *a
   end
+  # Performance shortcut
+  def self.color_for *a; @@instance.color_for *a; end
 end
 
 end
diff --git a/lib/sup/modes/scroll-mode.rb b/lib/sup/modes/scroll-mode.rb
index c131425..0ed26ea 100644
--- a/lib/sup/modes/scroll-mode.rb
+++ b/lib/sup/modes/scroll-mode.rb
@@ -12,8 +12,6 @@ class ScrollMode < Mode
 
   attr_reader :status, :topline, :botline, :leftcol
 
-  COL_JUMP = 2
-
   register_keymap do |k|
     k.add :line_down, "Down one line", :down, 'j', 'J', "\C-e"
     k.add :line_up, "Up one line", :up, 'k', 'K', "\C-y"
@@ -98,19 +96,23 @@ class ScrollMode < Mode
   def search_start_line; @topline end
   def search_goto_line line; jump_to_line line end
 
+  def col_jump
+    $config[:col_jump] || 2
+  end
+
   def col_left
     return unless @leftcol > 0
-    @leftcol -= COL_JUMP
+    @leftcol -= col_jump
     buffer.mark_dirty
   end
 
   def col_right
-    @leftcol += COL_JUMP
+    @leftcol += col_jump
     buffer.mark_dirty
   end
 
   def jump_to_col col
-    col = col - (col % COL_JUMP)
+    col = col - (col % col_jump)
     buffer.mark_dirty unless @leftcol == col
     @leftcol = col
   end
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index e58285e..3681180 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -212,7 +212,8 @@ class String
   ## the utf8 regex and count those. otherwise, use the byte length.
   def display_length
     if RUBY_VERSION < '1.9.1' && ($encoding == "UTF-8" || $encoding == "utf8")
-      scan(/./u).size
+      # scan hack is somewhat slow, worth trying to cache
+      @display_length ||= scan(/./u).size
     else
       size
     end
-- 
1.5.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

             reply	other threads:[~2010-12-30 23:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-30 23:35 Tero Tilus [this message]
2010-12-31  0:10 ` Rich Lane
2010-12-31  0:34   ` Tero Tilus
2010-12-31  1:44     ` Tero Tilus
2010-12-31  3:18       ` Tero Tilus
2011-01-19  3:15         ` Rich Lane
2011-01-19  3:13 ` Rich Lane

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1293750761-sup-3852@tilus.net \
    --to=tero@tilus.net \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox