Gnus development mailing list
 help / color / mirror / Atom feed
From: David Moore <dmoore@UCSD.EDU>
Subject: Re: Quicker exit and re-enter of large groups
Date: 08 Jan 1997 16:10:21 -0800	[thread overview]
Message-ID: <rvohezso7m.fsf@sdnp5.ucsd.edu> (raw)
In-Reply-To: Ken Raeburn's message of 08 Jan 1997 13:12:16 -0800

Ken Raeburn <raeburn@cygnus.com> writes:
> I do likewise.  Last time I did some profiling, gnus-dd-mmm took a big
> chunk of that time -- nearly a third.  It's called for every message.
> Can we speed it up somehow?  Or, more to the point, cut the cost of a
> large number of invocations, perhaps with some sort of caching?

	You have '%d' in your gnus-summary-line-format which is your
gnus-dd-mmm cost.  You could always take it out. ;-)


	More seriously, here's a semi-package I wrote a while back to do
generic caching on pure functions (ie ones whose result only depends on
their arguments).  I had meant to clean it up and rewrite it to be a bit
more general for supporting even situations where you don't have pure
functions but the other variables don't change very often.  Hmm, and
this version uses defadvice, which I had planned to change before I
tried to convince Lars to slap it into Gnus around various things.

In your .gnus stick in something like:
(require 'cachize)
(cachize 'gnus-dd-mmm 10000)
(cachize 'mail-extract-address-components 5000)

	If you use bbdb to mark known posters, definitely use the second
one, it'll speed up summary display by an order of magnitude on large
groups.

	Note the cache is LRU, and each slot in it takes 20 bytes.  But
if you make the number of slots too small, you can thrash on the cache.
Of course, this'll make it have slighly worse performance. :)


;;; David Moore <dmoore@ucsd.edu>
;;; This uncommented caching code is in the public domain.  Enjoy.
;;;
;;; Usage:
;;;
;;; (require 'cachize)
;;; (cachize 'mail-extract-address-components 5000)
;;;
;;; Yep, that's right, no operations to resize the cache or flush them, etc.
;;; You can use ad-unadvise to turn off the caching on a function.
;;;
;;; Note: be sure to only use this on pure functions.


(defvar cachize-data (make-hashtable 100 'eq))
(defvar cachize-info nil)		; overbound with let
(defmacro cachize-info-get-size ()
  `(aref cachize-info 0))

(defmacro cachize-info-get-cache ()
  `(aref cachize-info 1))

(defmacro cachize-info-get-cnt ()
  `(aref cachize-info 2))

(defmacro cachize-info-inc-cnt ()
  `(aset cachize-info 2 (1+ (aref cachize-info 2))))

(defmacro cachize-info-get-head ()
  `(aref cachize-info 3))

(defmacro cachize-info-set-head (head)
  `(aset cachize-info 3 ,head))

(defmacro cachize-info-get-tail ()
  `(aref cachize-info 4))

(defun cachize-pop (entry)
  (let ((next (aref entry 1))
	(prev (aref entry 2)))
  (when prev
    (aset prev 1 next))
  (when next
    (aset next 2 prev))
  (aset entry 1 nil)
  (aset entry 2 nil)))

(defun cachize-insert (entry)
  (let ((head (cachize-info-get-head)))
    (aset entry 1 (aref head 1))
    (aset entry 2 head)
    (aset head 1 entry)
    (aset (aref entry 1) 2 entry)))

(defun cachize (funsym size)
  (unless (gethash funsym cachize-data)
    (let* ((head (vector nil nil nil nil))
	   (tail (vector nil nil nil nil))
	   (info (vector size
			 (make-hashtable size 'equal)
			 0
			 head
			 tail)))
      (aset head 1 tail)
      (aset tail 2 head)
      (puthash funsym info cachize-data))
    (eval `(defadvice ,funsym (around cachize activate compile)
	     "This function is slow and therefore being cachized!"
	     (let* ((cachize-info (gethash (quote ,funsym) cachize-data))
		    (cachize-cache (cachize-info-get-cache)))
	       (when (>= (cachize-info-get-cnt) (cachize-info-get-size))
		 (let ((old (aref (cachize-info-get-tail) 2)))
		   (cachize-pop old)
		   (remhash (aref old 3) cachize-cache)))
	       (let ((cachize-entry (gethash (ad-get-args 0) cachize-cache)))
		 (unless cachize-entry
		   (cachize-info-inc-cnt)
		   (let ((args (copy-tree (ad-get-args 0))))
		     (setq cachize-entry (vector nil nil nil args))
		     (puthash args cachize-entry cachize-cache))
		   ad-do-it
		   (aset cachize-entry 0 ad-return-value))
		 (cachize-pop cachize-entry)
		 (cachize-insert cachize-entry)
		 (setq ad-return-value (aref cachize-entry 0))))))))
					     

(provide 'cachize)


-- 
David Moore <dmoore@ucsd.edu>       | Computer Systems Lab      __o
UCSD Dept. Computer Science - 0114  | Work: (619) 534-8604    _ \<,_
La Jolla, CA 92093-0114             | Fax:  (619) 534-1445   (_)/ (_)
<URL:http://oj.egbt.org/dmoore/>    |


  reply	other threads:[~1997-01-09  0:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-08 14:52 Kai Grossjohann
1997-01-08 16:21 ` Wesley.Hardaker
1997-01-08 16:39   ` Kai Grossjohann
1997-01-08 21:12     ` Ken Raeburn
1997-01-09  0:10       ` David Moore [this message]
1997-01-09 11:07 ` Lars Magne Ingebrigtsen
1997-01-09 18:16   ` Hunter Kelly
1997-01-09 21:10     ` Sudeep Kumar Palat

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=rvohezso7m.fsf@sdnp5.ucsd.edu \
    --to=dmoore@ucsd.edu \
    /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;
as well as URLs for NNTP newsgroup(s).