From xemacs-m  Fri May 30 00:45:00 1997
Received: from bittersweet.inetarena.com (karlheg@bittersweet.inetarena.com [206.129.216.38])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id AAA14553
	for <xemacs-beta@xemacs.org>; Fri, 30 May 1997 00:44:57 -0500 (CDT)
Received: (from karlheg@localhost)
	by bittersweet.inetarena.com (8.8.5/8.8.5) id WAA06547;
	Thu, 29 May 1997 22:44:16 -0700
Date: Thu, 29 May 1997 22:44:16 -0700
Message-Id: <199705300544.WAA06547@bittersweet.inetarena.com>
From: "Karl M. Hegbloom" <karlheg@inetarena.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: <xemacs-beta@xemacs.org>
Subject: patch: simple regex speedup.
X-Mailer: VM 6.31 under 20.3 XEmacs Lucid (beta2)
X-Face: /Q}=yl}1_v7nP)xXo5XjG8+tl@=uVu7o5u6)f]zN?+<hB!K.m9:[|*p34jVN`O;:XZXVSy>/\R>qDt(t8w!-i{(y0"`jFw^uk8inzO9wXabd'CdjUWfC\GHi:6nO*YC89#-qD>Q4r%9!V"<RYJ=7D#$";q=zML5'!=wvXk^$`6FT=5CMofQX)WUKt0p:OKl.mFOXx/D

                REGEXP_CACHE_SIZE in src/search.c
                ---------------------------------
 I'm reading the O'Reilly book on Regular Expressions[1] right now,
and on pg. 197-198, it says:

8<----------------------------------------------------------------->8
 As explained  in "Compile   Caching" (->  158), a  regex  is normally
compiled each time it is used, but Emacs caches the most-recently-used
regexes.  As of version 19.33, it caches five, but it will cache 20 in
a future version.*  Increasing the cache size was extremely beneficial
to the  example benchmarked in  Chapter 5 (-> 178),  but  that test is
pretty much  a worst-case situation for the cache.  I did some simple,
real-world tests using  automatic buffer indentaion  and fontification
routines (which make heavy use of  regular expressions), and found the
larger  cache size  won  about a  20 percent  improvement.   Still, 20
percent is nothing to sneez at!

 * A few days before this book went to final copyedit, I told Richard
 Stallman about the benchmark in Chapter 5, and he decided to bump up
 the cache size to 20, and also made the cache search some-what more
 efficient.  These changes should appear in a future version of Emacs.
8<----------------------------------------------------------------->8

Q: Are the cache search optimizations mentioned in the book part of
   the XEmacs regex engine?  Or do they need to be merged from the
   FSF version?

  Here is a patchlette to src/search.c:
8<----------------------------------------------------------------->8
*** search.c~	Mon Mar  3 18:30:12 1997
--- search.c	Thu May 29 22:28:25 1997
***************
*** 41,47 ****
  #include "regex.h"
  
  
! #define REGEXP_CACHE_SIZE 5
  
  /* If the regexp is non-nil, then the buffer contains the compiled form
     of that regexp, suitable for searching.  */
--- 41,47 ----
  #include "regex.h"
  
  
! #define REGEXP_CACHE_SIZE 20
  
  /* If the regexp is non-nil, then the buffer contains the compiled form
     of that regexp, suitable for searching.  */
8<----------------------------------------------------------------->8


Footnotes: 
[1]  "Mastering Regular Expressions", Jeffrey E.F. Friedl,
     ISBN 1-56592-257-3, O'Reilly and Associates, Inc.1997
       --- A *very* Excellent book!

-- 
Karl M. Hegbloom <karlheg@inetarena.com>
http://www.inetarena.com/~karlheg
Portland, OR  USA
Debian GNU 1.2  Linux 2.1.36 AMD K5 PR-133

