|
I'm using the C# .NET implementation of a regular expression. It's single threaded, which is to be expected, but instantiating a RegularExpression object is, well, a critical path - it takes a lock.
Another developer had written a class that used Regular Expressions to parse out some information from a string. The class was written so that every parsing created a new reg ex object, instead of doing that once, and calling its match method. I broke this out onto each CPU on the host machine, and with 24 threads, I'd get 40 parses per second. With 1 thread, I'd also get 40 parses per second. Fixing this bug and making the class stateful, to reuse the object it had created, I got the performance up to almost 2,000 parses per second, using all 24 cores.
What that tells me, especially that using more threads on more CPUs got us nothing, is that the .NET RegularExpression object takes a lock in the cctor. That you can only create 1 object at a time, no matter how powerful the host machine is.
|