Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx.Match is much slower in IIS compared to Development Server (Cassini)?

While looking at the performance of an asp.net (webservice) application, we noticed that on IIS it is much slower (38 seconds) than on the Dev Server (18 seconds). Running the Performance profiler (in sampling mode) of Visual studio we noticed the difference is calling regex.Match?! In IIS it is taking 70% of the time, running the same test against same app in dev server, it is taking less than 1% of the total time.

So anyone can explain this weird difference in behaviour between IIS and Dev Server??? I already tried stuff with different application pool setting... but nothing helped

like image 512
Tjipke Avatar asked Jul 06 '12 15:07

Tjipke


1 Answers

Found it!

It seems to be because IIS is running it in 64 bit (and casinni probably in 32 bit). By switching the application pool to use 32 bit, it is also fast in IIS, resetting it back to 64 bit and it is slow again.

By searching on 64 bit + regex slow, I also found that people already found this in 2006, and also that it was supposed to be fixed in a sp on .NET 2.0 (see: http://blogs.msdn.com/b/bclteam/archive/2007/05/21/the-regexoptions-compiled-flag-and-slow-performance-on-64-bit-net-framework-2-0-josh-free.aspx)

However I use .NET 4.0, so I would not have expected that issue to still exist...

(On stackoverflow see also: Regex slow on Windows Server 2008)

B.T.W. if I do not use the RegexOptions.Compiled when creating the regex, it also performs fast on 64 bit. But I need to do some benchmarking to see what the effect of not compiling it is on 32 bit.

like image 137
Tjipke Avatar answered Sep 20 '22 15:09

Tjipke