[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: pages with many images slow



jidanni@xxxxxxxxxxx writes:

> One could compare the time it takes to load a page with lots of images
> like http://commons.wikimedia.org/wiki/Category:PD_US_Military with
> emacs-w3m vs. midori.
> I think emacs-w3m wastes a lot of time with all those Reading...
> messages, which cause the minibuffer to resize if they don't fit, etc.

I think removing the messages wouldn't solve the core of the
problem. When you push `T' (or browse new page with
`w3m-default-display-inline-images' t), emacs-w3m run w3m for all the
images in the page at a time. This cause emacs to wait until all the
processes are invoked. So the more images there are in a page you
browse, the slower emacs-w3m would be, and this slowness depends on the
number of images.

BTW I wrote a patch to delay the process invoking. Could you try
this? I hope you like it :)

Regards,

For Japanese developers:

emacs-w3m は `T' などで画像を読みこむさいに一度に w3m を起動してしまって
います。 このため画像が大量にあるページでは全てのプロセスを起動するま
で操作ができず待たなければいけません。

実際、 elp で調べてみると w3m-toggle-inline-images の所要時間の大半が
w3m-create-image に費やされているようです。

.-------------------------------------------------------------------------------------
| w3m-toggle-inline-images                     1           35.562902     35.562902
| w3m-create-image                             193         31.116554000  0.1612256683
`-------------------------------------------------------------------------------------

そこで、 jit-lock のように run-with-idle-timer を使って Emacs が idle に
なる時まで w3m の起動を遅延させるパッチを書いてみました。 まだ少し荒削り
ですが試してみていただけますと幸いです。

--
青田
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1411
diff -u -r1.1411 w3m.el
--- w3m.el	21 Jan 2009 23:32:52 -0000	1.1411
+++ w3m.el	24 Jan 2009 08:11:37 -0000
@@ -3617,6 +3617,54 @@
 						    'help-echo help
 						    'balloon-help balloon)))))))))
 
+(defvar w3m-idle-images-show-timer nil)
+(defvar w3m-idle-images-show-list nil)
+(defvar w3m-idle-images-show-interval 1)
+(defun w3m-idle-images-show ()
+  (let ((repeat t))
+    (while (and repeat w3m-idle-images-show-list)
+      (setq w3m-idle-images-show-list (nreverse w3m-idle-images-show-list))
+      (let* ((item (car w3m-idle-images-show-list))
+	     (start    (nth 0 item))
+	     (end      (nth 1 item))
+	     (iurl     (nth 2 item))
+	     (url      (nth 3 item))
+	     (no-cache (nth 4 item))
+	     (size     (nth 5 item)))
+	(when (buffer-live-p (marker-buffer start))
+	  (w3m-process-with-null-handler
+	    (lexical-let ((start start)
+			  (end end)
+			  (iurl iurl)
+			  (url url))
+	      (w3m-process-do
+		  (image (let ((w3m-current-buffer (current-buffer)))
+			   (w3m-create-image
+			    iurl no-cache
+			    url
+			    size handler)))
+		(when (buffer-live-p (marker-buffer start))
+		  (with-current-buffer (marker-buffer start)
+		    (if image
+			(when (equal url w3m-current-url)
+			  (let (buffer-read-only)
+			    (w3m-insert-image start end image iurl))
+			  ;; Redisplay
+			  (when w3m-force-redisplay
+			    (sit-for 0)))
+		      (let (buffer-read-only)
+			(w3m-add-text-properties
+			 start end '(w3m-image-status off))))
+		    (set-buffer-modified-p nil))
+		  (set-marker start nil)
+		  (set-marker end nil)))))))
+      (setq w3m-idle-images-show-list 
+	    (nreverse (cdr w3m-idle-images-show-list)))
+      (setq repeat (sit-for 0.1 nil)))
+    (unless w3m-idle-images-show-list
+      (cancel-timer w3m-idle-images-show-timer)
+      (setq w3m-idle-images-show-timer nil))))
+
 (defsubst w3m-toggle-inline-images-internal (status
 					     &optional no-cache url
 					     begin-pos end-pos)
@@ -3674,32 +3722,19 @@
 You are retrieving non-secure image(s).  Continue? ")
 				      (message nil))
 				    (setq allow-non-secure-images t))))
-		  (w3m-process-with-null-handler
-		    (lexical-let ((start (set-marker (make-marker) start))
-				  (end (set-marker (make-marker) end))
-				  (iurl (w3m-url-transfer-encode-string iurl))
-				  (url w3m-current-url))
-		      (w3m-process-do
-			  (image (let ((w3m-current-buffer (current-buffer)))
-				   (w3m-create-image
-				    iurl no-cache
+		  (setq w3m-idle-images-show-list
+			(cons (list (set-marker (make-marker) start)
+				    (set-marker (make-marker) end)
+				    (w3m-url-transfer-encode-string iurl)
 				    w3m-current-url
-				    size handler)))
-			(when (buffer-live-p (marker-buffer start))
-			  (with-current-buffer (marker-buffer start)
-			    (if image
-				(when (equal url w3m-current-url)
-				  (let (buffer-read-only)
-				    (w3m-insert-image start end image iurl))
-				  ;; Redisplay
-				  (when w3m-force-redisplay
-				    (sit-for 0)))
-			      (let (buffer-read-only)
-				(w3m-add-text-properties
-				 start end '(w3m-image-status off))))
-			    (set-buffer-modified-p nil))
-			  (set-marker start nil)
-			  (set-marker end nil)))))))))
+				    no-cache
+				    size)
+			      w3m-idle-images-show-list))
+		  (unless w3m-idle-images-show-timer
+		    (setq w3m-idle-images-show-timer
+			  (run-with-idle-timer w3m-idle-images-show-interval
+					       t
+					       'w3m-idle-images-show)))))))
 	;; Remove.
 	(while (< (setq start (if (w3m-image end)
 				  end