Skip to main content

Posts

Showing posts from March, 2012

A Quick Tip About Using RegexOptions.Compiled

Since Silverlight doesn't support RegexOptions.Compiled, it's the one option that's missing from Regex Hero . In a full .NET application there may be times when it's worth it to use this option.  It adds significant cost to initializing the Regex instance, but it can also double the speed of the regular expression itself in some cases.  Therefore it's best to use when you can instantiate the Regex object once, and reuse it many times.  Jeff Atwood talks about this very point in his article, To Compile or Not to Compile . So if you've determined in your case that RegexOptions.Compiled is worth the initial cost of compilation, then I'm going to offer one simple solution that we as programmers often forget about. Lazy Loading The advantage with lazy loading is that the object we're concerned about is only instantiated when it's first accessed.  Therefore, we can use RegexOptions.Compiled without necessarily hurting the initial start-up time of ou

Faster Regex Syntax Highlighter

After the recent performance improvements to the analyzer I found that the next bottleneck was the regex syntax highlighter. You know, that's what paints your regular expression pretty colors. The slowness has probably affected fewer than 1% of the Regex Hero population. I say that because it was only really perceivable when dealing with a regular expression over 2,000 characters long. Nevertheless, I had an idea for how I can improve it. The slowness had nothing to do with parsing speed, and everything to do with how I was drawing the characters. I was dynamically adding characters in colored sections to a single text block to create the colored effect. This, as it turns out, is not optimal. So what I did is I created text blocks on top of eachother (one for each color), and then simply assign the appropriate text values to each one. For example, the text blocks might be composed of... test     (     )       \d\w           +   And since they're all on top

Faster Regex Analysis

Today I got rid of the tree view in the analyzer in favor of a staggered listbox. It was kind of cool to be able to expand or collapse individual items in the tree view, but it came at a cost.  The tree view is extremely slow when you're constantly updating it.  And of course, since everything in Regex Hero is supposed to happen in real-time, the tree view had to go. With today's changes the analyzer feature is now at least 5 times faster.  And with the staggered listbox we can still easily visualize the nested nature of a regular expression, as you can see in the example below...

Optimizing Your Regular Expressions

Regular expressions will backtrack.  That's an unfortunate thing about them because backtracking can be slow.    And in certain (rare) cases the performance can become so awful that executing the regular expression against a relatively short string could take over a minute.  There's a good article about catastrophic backtracking over at regular-expressions.info . And today I created a video about all of this called  Regex Lesson 5: Optimization .  In the video I start with a very poorly written regular expression and make several improvements to it, using the benchmarking feature along the way.  By the end of the video I make the regular expression over 3 million times faster. In addition, today's update to Regex Hero provides a little message in the event that you encounter a regular expression that takes over 10 seconds to evaluate... And then last of all, I changed the benchmarking feature a bit.  In the past it would simply test your regular expression against

Benchmarking Bug Fix

Today's update is a small one.  I discovered that under certain situations the benchmarking feature in Regex Hero would fail and return NaN values.  I solved this problem today so we shouldn't be seeing that again. I also made a couple recent changes to the site for better performance.  For one, I switched from the Rackspace CDN I was using back to Amazon CloudFront.  Amazon's CDN isn't necessarily the fastest in all countries, but it's very reliable and consistent.  Then I extended the cache/expiration settings for the site's CSS file and the loading screen for Regex Hero so repeat visitors should enjoy improved responsiveness.