[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pages with many images slow
- From: Naohiro Aota <naota@xxxxxxxxx>
- Date: Tue, 27 Jan 2009 01:37:39 +0900
- X-ml-name: emacs-w3m
- X-mail-count: 10639
- References: <87hc4d1yx4.fsf@xxxxxxxxxxx> <871vutozvb.fsf@xxxxxxxxxxxxxxxx> <b4mvds2bvpw.fsf@xxxxxxx> <87mydelbxf.fsf@xxxxxxxxxxxxxxxx> <b4mr62qigu1.fsf@xxxxxxx>
Katsumi Yamaoka <yamaoka@xxxxxxx> writes:
>>>>>> In [emacs-w3m : No.10637] Naohiro Aota wrote:
>> It seems I forgot to change buffer before calling
>> `w3m-create-image'. Could you try the new patch?
>
> Thanks. Works fine with one exception. IIUC, the main thing
> that slows displaying images is retrieving of image data from
> remote sites. Isn't it better not to use the idle-timer for
> cached images (including cid image data embedded in html articles)?
> Actually, when pressing the T key repeatedly for re-displaying
> cached images, unpatched w3m.el is faster than the patched one
> in my system.
To be exact, emacs-w3m waits for retrieving process creating or image
size conversion (if cached and need to resize). Anyway, I changed the
code to use the idle-timer system only when all the following conditions
are met.
1. the image is remote one
2. emacs-w3m doesn't have cache of the image
3. emacs-w3m doesn't need to resize the image
Now, I think the code is good enough to be tested in emacs-w3m CVS. If
there is no objection, I'll commit the code in the CVS.
;; Is it better to make `w3m-process-stop' to call
;; `w3m-idle-images-show-unqueue'?
Regards,
Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3198
diff -u -r1.3198 ChangeLog
--- ChangeLog 25 Jan 2009 20:35:43 -0000 1.3198
+++ ChangeLog 26 Jan 2009 16:30:41 -0000
@@ -1,3 +1,13 @@
+2009-01-27 Naohiro Aota <naota@xxxxxxxxx>
+
+ * w3m.el (w3m-idle-images-show-timer, w3m-idle-images-show-list)
+ (w3m-idle-images-show-interval): New variables.
+ (w3m-idle-images-show, w3m-idle-images-show-unqueue): New functions.
+ (w3m-toggle-inline-images-internal): Use them.
+ (w3m-toggle-inline-images, w3m-delete-buffer, w3m-delete-buffers)
+ (w3m-goto-url, w3m-region, w3m-select-buffer-delete-buffer): Unqueue
+ image retrieving process reservation.
+
2009-01-26 Naohiro Aota <naota@xxxxxxxxx>
* w3m.el (w3m-content-type-alist): Add "application/x-pdf" content
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1413
diff -u -r1.1413 w3m.el
--- w3m.el 26 Jan 2009 07:42:40 -0000 1.1413
+++ w3m.el 26 Jan 2009 16:30:44 -0000
@@ -3618,6 +3618,70 @@
'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))
+ (with-current-buffer (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))))
+
+(defun w3m-idle-images-show-unqueue (buffer)
+ (when w3m-idle-images-show-timer
+ (cancel-timer w3m-idle-images-show-timer)
+ (setq w3m-idle-images-show-list
+ (delq nil
+ (mapcar (lambda (x)
+ (and (not (eq buffer (marker-buffer (nth 0 x))))
+ x))
+ w3m-idle-images-show-list)))
+ (when w3m-idle-images-show-list
+ (run-with-idle-timer w3m-idle-images-show-interval
+ t
+ 'w3m-idle-images-show))))
+
(defsubst w3m-toggle-inline-images-internal (status
&optional no-cache url
begin-pos end-pos)
@@ -3675,32 +3739,49 @@
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
- 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)
+ (if (and (null (and size w3m-resize-images))
+ (or (string-match "\\`\\(?:cid\\|data\\):" iurl)
+ (w3m-url-local-p iurl)
+ (w3m-cache-available-p iurl)))
+ (w3m-process-with-null-handler
+ (lexical-let ((start (set-marker (make-marker) start))
+ (end (set-marker (make-marker) end))
+ (iurl iurl)
+ (url w3m-current-url))
+ (w3m-process-do
+ (image (let ((w3m-current-buffer (current-buffer)))
+ (w3m-create-image
+ iurl no-cache
+ 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-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)))))))))
+ (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
+ (cons (list (set-marker (make-marker) start)
+ (set-marker (make-marker) end)
+ (w3m-url-transfer-encode-string iurl)
+ w3m-current-url
+ 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
@@ -3851,7 +3932,9 @@
(w3m-toggle-inline-images-internal (if status 'on 'off)
no-cache nil beg end)
(setq w3m-display-inline-images (not status))
- (when status (w3m-process-stop (current-buffer)))
+ (when status
+ (w3m-process-stop (current-buffer))
+ (w3m-idle-images-show-unqueue (current-buffer)))
(force-mode-line-update)))
(w3m-message "There are some images considered unsafe;\
use the prefix arg to force display"))))
@@ -7226,6 +7309,7 @@
(delete-window))))))
(w3m-session-deleted-save (list cur))
(w3m-process-stop cur)
+ (w3m-idle-images-show-unqueue cur)
(kill-buffer cur)
(when w3m-use-form
(w3m-form-kill-buffer cur))
@@ -7304,6 +7388,7 @@
(while buffers
(setq buffer (pop buffers))
(w3m-process-stop buffer)
+ (w3m-idle-images-show-unqueue buffer)
(kill-buffer buffer)
(when w3m-use-form
(w3m-form-kill-buffer buffer))))
@@ -8709,6 +8794,7 @@
Cannot run two w3m processes simultaneously \
\(Type `\\<w3m-mode-map>\\[w3m-process-stop]' to stop asynchronous process)")))
(w3m-process-stop (current-buffer)) ; Stop all processes retrieving images.
+ (w3m-idle-images-show-unqueue (current-buffer))
;; Store the current position in the history structure.
(w3m-history-store-position)
;; Access url group
@@ -9315,6 +9401,7 @@
(or (buffer-file-name) default-directory))))
(save-restriction
(w3m-process-stop (current-buffer))
+ (w3m-idle-images-show-unqueue (current-buffer))
(narrow-to-region start end)
(w3m-clear-local-variables)
(let ((w3m-current-buffer (current-buffer)))
@@ -9988,6 +10075,7 @@
(let ((buffer (w3m-select-buffer-current-buffer)))
(forward-line -1)
(w3m-process-stop buffer)
+ (w3m-idle-images-show-unqueue buffer)
(kill-buffer buffer)
(when w3m-use-form
(w3m-form-kill-buffer buffer))