* [sup-devel] Scrolling (with patches)
@ 2010-12-30 23:35 Tero Tilus
2010-12-31 0:10 ` Rich Lane
2011-01-19 3:13 ` Rich Lane
0 siblings, 2 replies; 7+ messages in thread
From: Tero Tilus @ 2010-12-30 23:35 UTC (permalink / raw)
To: Sup developers
[-- 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Scrolling (with patches)
2010-12-30 23:35 [sup-devel] Scrolling (with patches) Tero Tilus
@ 2010-12-31 0:10 ` Rich Lane
2010-12-31 0:34 ` Tero Tilus
2011-01-19 3:13 ` Rich Lane
1 sibling, 1 reply; 7+ messages in thread
From: Rich Lane @ 2010-12-31 0:10 UTC (permalink / raw)
To: Tero Tilus; +Cc: Sup developers
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
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Scrolling (with patches)
2010-12-31 0:10 ` Rich Lane
@ 2010-12-31 0:34 ` Tero Tilus
2010-12-31 1:44 ` Tero Tilus
0 siblings, 1 reply; 7+ messages in thread
From: Tero Tilus @ 2010-12-31 0:34 UTC (permalink / raw)
To: Sup developers
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
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Scrolling (with patches)
2010-12-31 0:34 ` Tero Tilus
@ 2010-12-31 1:44 ` Tero Tilus
2010-12-31 3:18 ` Tero Tilus
0 siblings, 1 reply; 7+ messages in thread
From: Tero Tilus @ 2010-12-31 1:44 UTC (permalink / raw)
To: Sup developers
[-- Attachment #1: Type: text/plain, Size: 213 bytes --]
Tero Tilus, 2010-12-31 02:34:
> I think we could have Singleton.method_missing actually create the
> methods as they are called.
From words to deeds. ;)
--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
[-- Attachment #2: 0003-Improve-Singleton-performance.patch --]
[-- Type: application/octet-stream, Size: 972 bytes --]
From 3639fcc8d080af9db883c0823261b94b1b326a91 Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Fri, 31 Dec 2010 03:42:49 +0200
Subject: [PATCH] Improve Singleton performance
---
lib/sup/util.rb | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index 3681180..f1265d1 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -536,6 +536,14 @@ module Singleton
## special-case every call to a Singleton object
return nil if @instance.nil?
+ # Speed up further calls by defining a shortcut around method_missing
+ if meth.to_s[-1,1] == '='
+ # Argh! Inconsistency! Setters do not work like all the other methods.
+ class_eval "def self.#{meth}(a); @instance.#{meth}(a); end"
+ else
+ class_eval "def self.#{meth}(*a, &b); @instance.#{meth}(*a, &b); end"
+ end
+
@instance.send meth, *a, &b
end
def init *args
--
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Scrolling (with patches)
2010-12-31 1:44 ` Tero Tilus
@ 2010-12-31 3:18 ` Tero Tilus
2011-01-19 3:15 ` Rich Lane
0 siblings, 1 reply; 7+ messages in thread
From: Tero Tilus @ 2010-12-31 3:18 UTC (permalink / raw)
To: Sup developers
[-- Attachment #1: Type: text/plain, Size: 253 bytes --]
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.
--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
[-- Attachment #2: 0003-Improve-Singleton-performance.patch --]
[-- Type: application/octet-stream, Size: 984 bytes --]
From 9fd7a4f11709399219395320c9cdbf93c33f87fe Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Fri, 31 Dec 2010 03:42:49 +0200
Subject: [PATCH] Improve Singleton performance
---
lib/sup/util.rb | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index 3681180..f74ec6a 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -536,6 +536,14 @@ module Singleton
## special-case every call to a Singleton object
return nil if @instance.nil?
+ # Speed up further calls by defining a shortcut around method_missing
+ if meth.to_s[-1,1] == '='
+ # Argh! Inconsistency! Setters do not work like all the other methods.
+ class_eval "def self.#{meth}(a); @instance.send :#{meth}, a; end"
+ else
+ class_eval "def self.#{meth}(*a, &b); @instance.send :#{meth}, *a, &b; end"
+ end
+
@instance.send meth, *a, &b
end
def init *args
--
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Scrolling (with patches)
2010-12-30 23:35 [sup-devel] Scrolling (with patches) Tero Tilus
2010-12-31 0:10 ` Rich Lane
@ 2011-01-19 3:13 ` Rich Lane
1 sibling, 0 replies; 7+ messages in thread
From: Rich Lane @ 2011-01-19 3:13 UTC (permalink / raw)
To: Tero Tilus; +Cc: Sup developers
Applied to master.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-01-19 3:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-30 23:35 [sup-devel] Scrolling (with patches) Tero Tilus
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox