Regex slow on Windows Server 2008

前端 未结 3 1037
你的背包
你的背包 2021-01-13 06:53

I have a situation where my regular expressions compile extremely slowly on Windows Server 2008. I wrote a small console application to highlight this issue. The app gener

相关标签:
3条回答
  • 2021-01-13 07:14

    You can pre-compile your regexes using the Regex.CompileToAssembly method, and then you could deploy the compiled regexes to your server.

    0 讨论(0)
  • 2021-01-13 07:28

    I found a solution, given not the correct one, but perfect in my case. For some reason if I leave out the RegexOptions.Compiled flag, the Regex is much, much faster. I even managed to execute the Regex on 100 long phrases in under 65 milliseconds on the 2008 server.

    This must be a bug in the .net lib as the uncompiled version is supposed to be much slower than the compiled version. Either way, under 1 millisecond per check is very much acceptable for me :)

    0 讨论(0)
  • 2021-01-13 07:30

    I ran into the exact same problem. My app works fine on x86 machines but memory balloons and hangs on x64. Removing the compilation flag did not help. I tried this today on .net 4.0 and the problem remains. If you have a repro, I suggest you file a bug.

    I think MSFT knows about this, see the bottom comment here

    But let them decide if this is the same bug. Please add a link to your filing here if you file so I can add my comments to it.

    0 讨论(0)
提交回复
热议问题