emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <carsten.dominik@gmail.com>
To: Bastien <bzg@altern.org>
Cc: Christopher Schmidt <christopher@ch.ristopher.com>,
	"emacs-orgmode@gnu.org Mailing List" <emacs-orgmode@gnu.org>
Subject: Re: ...
Date: Thu, 31 Jan 2013 12:59:29 +0100	[thread overview]
Message-ID: <CFA43917-9EBF-4215-90FE-6DC8535A1CFD@gmail.com> (raw)
In-Reply-To: <87622dlhqm.fsf@bzg.ath.cx>

Hi Bastien,

as you know, regular expressions are a language to do a programmed search for text.  The pattern string has to be compiled before it can be used.  That compilation is a costly process, so most languages that have pattern matching use some kind of cache to store compiled patterns, so that frequently used patterns can be reused without compilation.

I am aware of this very much from studying perl.  In perl, a compiled pattern is associated with a particular instance of a string.  Often you build the pattern by constructing it through concatenation of other parts etc.  In Perl this means that the pattern is recompiled each time a match.  You can work around this issue in Perl by telling it explicitly and on programmers authority that, "yes, this pattern is dynamically constructed, but only once, I guarantee that it will not change, so compile it only once".  So in Perl the difference is

/pattern/      will match against pattern
/$pattern/     will match agains the pattern contained in the
               variable $pattern, and recompilation will occur
               each time
/$pattern/o    will compile only once and trust the programmer.

So I am very aware of this speedup issue.  And I thought that in Emacs, the caching would work by associating a specific string object with the compiled pattern.  But the code Christopher pointed out seems to suggest that the pattern cache works also for strings that are `equal', not only for string that are `eq'.

If this is the case, this means that there is only a very small difference between

(defconst my-pattern (concat "^" "xyz"))
(re-search-forward my-pattern ....)      ; many times in different functions

and

(defconst my-partial-pattern "xyz")
(re-search-forward (concat "^" my-partial-pattern) ....)  ; many times

The difference is only the repeated concatenation operation, and not the recompilation.  I always thought that this would work differently, and that is why a lot of regexps get constructed and then stored in variables or constants.  Of course this is also a good practice for readable and maintainable code, but the impact on efficiency is not as big as I used to think.  So when I saw Christoher's initial patch, I thought a function to create
org-ooutline-regexp-bol would be a large burden in speed - but it now seems that it would only be a minor impact.

Still, I think making a local variable in buffers with org-struct-mode is also a good way to get the functionality Christopher wants.

Clearer?

- Carsten


On 31 jan. 2013, at 12:22, Bastien <bzg@altern.org> wrote:

> Hi Carsten and Christopher,
> 
> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
>> I mant to copy the list, I am doing this again now.
>> 
>> Wow, I was not aware that Emacs caches by content, this is an important
>> piece of information.  I guess this removed the main concern I had.  Thanks
>> for looking it up in the code and showing it to me.  I am not sure if I
>> understand that code completely, but i trust your judgment.
> 
> I'm not sure I have all the background to understand the issue at
> stake... can anyone educate me?  Thanks!
> 
> -- 
> Bastien


-- 
There is no unscripted life.  Only a badly scripted one. -- Brothers Bloom

  parent reply	other threads:[~2013-01-31 11:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <877gmt3dzq@ch.ristopher.com>
     [not found] ` <871ud13dkp@ch.ristopher.com>
2013-01-31 10:37   ` Carsten Dominik
2013-01-31 10:53     ` Christopher Schmidt
2013-01-31 13:40       ` Bastien
2013-01-31 11:22     ` Bastien
2013-01-31 11:46       ` roundtrip integration with Asana? Meng Weng Wong
2013-01-31 13:49         ` Bastien
2013-02-01  2:53           ` Meng Weng Wong
2013-01-31 11:59       ` Carsten Dominik [this message]
2013-01-31 13:32         ` Bastien
2013-01-31 14:32           ` Carsten Dominik
2013-01-31 16:02             ` orgstruct-mode with custom headline prefix (was: ...) Christopher Schmidt

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CFA43917-9EBF-4215-90FE-6DC8535A1CFD@gmail.com \
    --to=carsten.dominik@gmail.com \
    --cc=bzg@altern.org \
    --cc=christopher@ch.ristopher.com \
    --cc=emacs-orgmode@gnu.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).