[mew-dist 28990] cmewのほんの僅かな処理速度の改善

Takahiro Kambe taca at example.com
2009年 9月 8日 (火) 19:14:04 JST


こんにちは。

Mew 6.xでcmew/smewにRubyと、そのsqlite3サポートが使用されていることに、
今頃気が付きました。cmew/smewが(#!の関係で)起動できなくて気が付いたの
ですが、さらにcmewが存在しないsqlite3のライブラリをロードできず、一瞬
で終了していることにしばらく後で気が付きました。

以上は単なる前置きなのですが、時間かけて動作しているcmewのプロセスに
何気なくktrussをかけて、妙にstat(2)の呼び出しが多いことに気が付きまし
た。Rubyの File.find を呼び出して得たパス名を処理する過程で、複数回の
実行が必要となるのは仕方がないのですが、

 29048      1 ruby18   __lstat50("./dovecot/7172", 0xbfbec894) = 0
 29048      1 ruby18   __stat50("./dovecot/7172", 0xbfbec89c) = 0
 29048      1 ruby18   __stat50("./dovecot/7172", 0xbfbeb0ec) = 0
 29048      1 ruby18   __stat50("./dovecot/7172", 0xbfbe9914) = 0
 29048      1 ruby18   __fstat50(0x5, 0xbfbe68c0)  = 0
 29048      1 ruby18   __stat50("./dovecot/7172", 0xbfbee74c) = 0
 29048      1 ruby18   __lstat50("./dovecot/7172", 0xbfbeb7e4) = 0

といった感じでした。ちょっとだけ手直しすると、といった辺りまで減らせま
した。

 21245      1 ruby18   __lstat50("./kbug-users-2003/338", 0xbfbec894) = 0
 21245      1 ruby18   __fstat50(0x6, 0xbfbe68c0)  = 0
 21245      1 ruby18   __stat50("./kbug-users-2003/338", 0xbfbee74c) = 0
 21245      1 ruby18   __lstat50("./kbug-users-2003/338", 0xbfbeb7e4) = 0

システムコールの呼び出しは、それなりのオーバーヘッドもありますので、
貯めてるメールの数や環境によっては効果があるかもしれません。

変更点を見るための修正は以下のようになります。インデントも含めた修正の
パッチは、このメールに同封します。


--- bin/cmew.orig	2009-09-08 14:47:50.000000000 +0900
+++ bin/cmew	2009-09-08 15:16:23.000000000 +0900
@@ -134,28 +134,30 @@
         Find.prune # includes next
       end
       # next
-    elsif FileTest.symlink?(fpath)
+    else
+      st = File.lstat(fpath)
+      if st.symlink?
       if FileTest.directory?(fpath)
         print fpath, " (ignored)\n"
         Find.prune # includes next
       end
       # next      
-    elsif FileTest.directory?(fpath)
+      elsif st.directory?
       print fpath
       mtime_file = File.expand_path('.mew-mtime', fpath)
       if FileTest.file?(mtime_file) and last_mod > File.mtime(mtime_file).tv_sec
         print " (skipped)\n"
         skipdir = fpath
-        if File::stat(fpath).nlink == 2
+          if st.nlink == 2
           Find.prune # includes next          
         end
       else
         print "\n"
       end
       # next
-    elsif FileTest.file?(fpath) and fpath =~ /\/[0-9]+(\.mew)?$/
+      elsif st.file? and fpath =~ /\/[0-9]+(\.mew)?$/
       next if File.dirname(fpath) == skipdir
-      next if last_mod > File.ctime(fpath).tv_sec
+        next if last_mod > st.ctime.tv_sec
       m = Mail.new(fpath)
       id = get_id(m)
       parid = get_parid(m)
@@ -179,6 +181,7 @@
       # next
     end
   end
+  end
   add_entry.close
   get_entry.close
   del_entry.close


-- 
神戸 隆博(かんべ たかひろ)		at 仕事場 

-------------- next part --------------
テキスト形式以外の添付ファイルを保管しました...
ファイル名: cmew-patch
型:         application/octet-stream
サイズ:     3046 バイト
説明:       無し
URL:        <http://www.mew.org/pipermail/mew-dist/attachments/20090908/590b9b06/attachment.obj>


Mew-dist メーリングリストの案内