« MBS Xojo Plugins, ver… | Home | Xojo Leak Finder »

RegEx Speedup

Did you notice the RegExMBS Speedup in MBS Xojo Plugins version 21.1pr2?

We recently got a notice about our plugin being slow with RegEx. A test project showed it is even slower than the built-in RegEx class in Xojo, so I looked what we could optimize.

The sample benchmark example (attache to Feedback case 24836) just creates a string with given number of matches and then lets the Xojo and the MBS class look for matches and counts them.

Size Xojo RegEx MBS 20.0 MBS 21.0 MBS 21.1pr3
500 Matches in 1 MB 186.826 msec 359.175 msec 285.546 msec 7.737 msec
5000 Matches in 10 MB 19.338.806 msec 35.494.294 msec 29.938.579 msec 56.555 msec
50000 Matches in 10 MB 19.508.207 msec 316.821.069 msec 292.339.023 msec 58.222 msec

Those numbers are measured here in built 64-bit apps with disabled background tasks. Your numbers may vary with a different CPU, but the relations should be reproducible for you.

As usual for the majority of Xojo developers the built-in classes are fine. And we cater to the small percentage, which needs a little bit more performance. But the new speeds measured are phenomenal.

How did we speed up? Well for MBS Plugin, we used to do a check whether a string is ASCII or UTF-8 and this check takes some time and if you do that on each call, it may kill performance. You see it exactly above as the number of matches defines how often Execute() is called and so how often the plugin did the string check. For our plugin, the check is now made only once and then we see you pass the same string, we skip it for further calls and use cached result.

Please try and let us know. Especially we are looking for similar cases where you pass the same text again and again.

The biggest plugin in space...
08 02 21 - 09:26