<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: JS RegEx&#8217;s Are Slow</title>
	<atom:link href="http://infrequently.org/2007/02/regexs-are-slow/feed/" rel="self" type="application/rss+xml" />
	<link>http://infrequently.org/2007/02/regexs-are-slow/</link>
	<description></description>
	<lastBuildDate>Mon, 05 Dec 2011 10:29:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: David Durand</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-165065</link>
		<dc:creator>David Durand</dc:creator>
		<pubDate>Mon, 20 Aug 2007 19:07:22 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-165065</guid>
		<description>Regexp compilation can slow things (as noted by Joseph Smarr), but the article that you cite is about regexp matching finding a first match for a given regexp.

Replacement can be slow because there may be many matches for a given expression, and replacement often involves named subexpressions ($1, etc. which change the inherent execution time a lot).

Any string changes will test the string representation implementation (and often the storage manager it uses). If the string representation can&#039;t share structure with the original string, a new string has to be allocated -- that&#039;s slow, and the string has to be copied. If the number of matches grows with the size of the string, the performance is going to deteriorate in an n**2 fashion, because of all the copying. 

A string representation that uses sharing and pointer structures to avoid copying is more complex, and you will pay for the faster substitutions with slower access and updates to the string because it&#039;s not an indexable buffer of character code points.

Such structures can also introduce garbage-collection issues as portions deleted from a string may still be in memory, in the original character-buffers.

This is an implementation area that&#039;s been hard to optimize since the original classic papers on string-processing languages in the 1960&#039;s. Look up Griswold and Snobol.</description>
		<content:encoded><![CDATA[<p>Regexp compilation can slow things (as noted by Joseph Smarr), but the article that you cite is about regexp matching finding a first match for a given regexp.</p>
<p>Replacement can be slow because there may be many matches for a given expression, and replacement often involves named subexpressions ($1, etc. which change the inherent execution time a lot).</p>
<p>Any string changes will test the string representation implementation (and often the storage manager it uses). If the string representation can&#8217;t share structure with the original string, a new string has to be allocated &#8212; that&#8217;s slow, and the string has to be copied. If the number of matches grows with the size of the string, the performance is going to deteriorate in an n**2 fashion, because of all the copying. </p>
<p>A string representation that uses sharing and pointer structures to avoid copying is more complex, and you will pay for the faster substitutions with slower access and updates to the string because it&#8217;s not an indexable buffer of character code points.</p>
<p>Such structures can also introduce garbage-collection issues as portions deleted from a string may still be in memory, in the original character-buffers.</p>
<p>This is an implementation area that&#8217;s been hard to optimize since the original classic papers on string-processing languages in the 1960&#8242;s. Look up Griswold and Snobol.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mihai</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-80940</link>
		<dc:creator>Mihai</dc:creator>
		<pubDate>Sat, 17 Feb 2007 16:38:57 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-80940</guid>
		<description>&lt;a href=&quot;http://perlmonks.org/?node_id=597262&quot; rel=&quot;nofollow&quot;&gt;Perl regexp matching is slow??&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p><a href="http://perlmonks.org/?node_id=597262" rel="nofollow">Perl regexp matching is slow??</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ajax Performance &#187; Catching up on the news bin</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-78556</link>
		<dc:creator>Ajax Performance &#187; Catching up on the news bin</dc:creator>
		<pubDate>Wed, 07 Feb 2007 15:42:09 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-78556</guid>
		<description>[...] In other Dojo news, Alex Russell posted a brief gripe about the incredible slowness of regular expressions, especially for replacements. The gripe included a link to a very detailed survey of regex suckage on multiple platforms, for those who want the deep dive. [...]</description>
		<content:encoded><![CDATA[<p>[...] In other Dojo news, Alex Russell posted a brief gripe about the incredible slowness of regular expressions, especially for replacements. The gripe included a link to a very detailed survey of regex suckage on multiple platforms, for those who want the deep dive. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Philip Tellis</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-78545</link>
		<dc:creator>Philip Tellis</dc:creator>
		<pubDate>Wed, 07 Feb 2007 15:15:22 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-78545</guid>
		<description>I&#039;ve found however, that some regex string replaces are faster than a substr.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve found however, that some regex string replaces are faster than a substr.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-78482</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Wed, 07 Feb 2007 12:41:53 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-78482</guid>
		<description>Oh dear, looks like something went wrong when I uploaded selector.js this morning and I won&#039;t be able to update it for a day or two. Serves me right for using freebie hosting. Until I fix it, here&#039;s a link to a &lt;a href=&quot;http://daniel_james.fmail.co.uk/selector.js&quot; rel=&quot;nofollow&quot;&gt;working (ish) version&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Oh dear, looks like something went wrong when I uploaded selector.js this morning and I won&#8217;t be able to update it for a day or two. Serves me right for using freebie hosting. Until I fix it, here&#8217;s a link to a <a href="http://daniel_james.fmail.co.uk/selector.js" rel="nofollow">working (ish) version</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-78392</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Wed, 07 Feb 2007 08:35:45 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-78392</guid>
		<description>I think you&#039;re being premature. Profiling suggests that in my code &#039;toXPath&#039; takes about 2% of the execution time of the XPath version.

I&#039;m sure it could be optimized further, by replacing some of the regular expressions but I&#039;d be very suprised if you could improved on the speed of the &#039;tokenise&#039; function without sacrificing accuracy (of course, it can immediately be improved by removing the validation).</description>
		<content:encoded><![CDATA[<p>I think you&#8217;re being premature. Profiling suggests that in my code &#8216;toXPath&#8217; takes about 2% of the execution time of the XPath version.</p>
<p>I&#8217;m sure it could be optimized further, by replacing some of the regular expressions but I&#8217;d be very suprised if you could improved on the speed of the &#8216;tokenise&#8217; function without sacrificing accuracy (of course, it can immediately be improved by removing the validation).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph Smarr</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-78343</link>
		<dc:creator>Joseph Smarr</dc:creator>
		<pubDate>Wed, 07 Feb 2007 05:51:55 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-78343</guid>
		<description>Alex-dunno if this helps, but I did a lot of performance tuning with Regexes in Java, and one surprising finding was that in many cases constructing the regex was the main slowdown and using it to match wasn&#039;t so bad in addition. So a little indexOf to test if we had a prayer of matching before taking the hit to construct the regex did wonders. That doesn&#039;t answer the root question (why are they slow at all), but it may be of use in the short term.

PS: Your cool WYSYWIG editor box for comments doesn&#039;t work for me in IE7 (a normal textarea shows up underneath the submit button and when I submit it says nothing was entered.)</description>
		<content:encoded><![CDATA[<p>Alex-dunno if this helps, but I did a lot of performance tuning with Regexes in Java, and one surprising finding was that in many cases constructing the regex was the main slowdown and using it to match wasn&#8217;t so bad in addition. So a little indexOf to test if we had a prayer of matching before taking the hit to construct the regex did wonders. That doesn&#8217;t answer the root question (why are they slow at all), but it may be of use in the short term.</p>
<p>PS: Your cool WYSYWIG editor box for comments doesn&#8217;t work for me in IE7 (a normal textarea shows up underneath the submit button and when I submit it says nothing was entered.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-77951</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Tue, 06 Feb 2007 13:41:31 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-77951</guid>
		<description>Hey Philip,

So my comment about replacement is mostly due to the apparent inefficiency in the process, not a simple-minded &quot;why are they slower than matching?&quot; kind of comment. Clearly they&#039;ll be slower, but there&#039;s no justification for them being as slow as they are today.

For instance, when tuning the template system in Dojo, we looked at using regexps to speed up attribute matching, but the speed of replacement was such that it was faster to iterate recursively over the resulting DOM than to use regexps. Weirdly, it was the same story on FF and IE. There&#039;s something rotten there.

Regards</description>
		<content:encoded><![CDATA[<p>Hey Philip,</p>
<p>So my comment about replacement is mostly due to the apparent inefficiency in the process, not a simple-minded &#8220;why are they slower than matching?&#8221; kind of comment. Clearly they&#8217;ll be slower, but there&#8217;s no justification for them being as slow as they are today.</p>
<p>For instance, when tuning the template system in Dojo, we looked at using regexps to speed up attribute matching, but the speed of replacement was such that it was faster to iterate recursively over the resulting DOM than to use regexps. Weirdly, it was the same story on FF and IE. There&#8217;s something rotten there.</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Philip Tellis</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-77938</link>
		<dc:creator>Philip Tellis</dc:creator>
		<pubDate>Tue, 06 Feb 2007 13:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-77938</guid>
		<description>To speed up regex matches, anchor your strings.

/^foo$/i is faster than /foo/i when you want to match the whole string.

string replacement would be slower than just matching because it&#039;s a write operation rather than read.</description>
		<content:encoded><![CDATA[<p>To speed up regex matches, anchor your strings.</p>
<p>/^foo$/i is faster than /foo/i when you want to match the whole string.</p>
<p>string replacement would be slower than just matching because it&#8217;s a write operation rather than read.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jesse</title>
		<link>http://infrequently.org/2007/02/regexs-are-slow/comment-page-1/#comment-77768</link>
		<dc:creator>jesse</dc:creator>
		<pubDate>Tue, 06 Feb 2007 05:17:59 +0000</pubDate>
		<guid isPermaLink="false">http://alex.dojotoolkit.org/?p=600#comment-77768</guid>
		<description>omg you&#039;re sick for reading through all of that. ...just sick&#160; =p</description>
		<content:encoded><![CDATA[<p>omg you&#8217;re sick for reading through all of that. &#8230;just sick&nbsp; =p</p>
]]></content:encoded>
	</item>
</channel>
</rss>

