3 ms·
What's slow about regex? A properly optimised regex engine ought to be very efficient (if used sensibly, at least).
by MaxBarraclough 2y ago
What's slow about regex? A properly optimised regex engine ought to be very efficient (if used sensibly, at least).
- steveklabnik 2y agostd::regex in C++ cannot be "properly optimized" due to various factors: https://stackoverflow.com/questions/70583395/why-is-stdregex-notoriously-much-slower-than-other-regular-expression-librarie https://stackoverflow.com/questions/70583395/why-is-stdregex...
- MaxBarraclough 2y agoThe answer there [0] doesn't support this. From the answer: > There is no question that libstdc++'s implementation of <regex> is not well optimized. But there is more to it than that. It's not that the standard requirements inhibit optimizations so much as the standard requirements inhibit changes. The answer's one comment expands on this, it sounds like they're not able to add a sophisticated optimising regex engine into the libstd++ shared library (i.e. non-inline) as this would be an ABI break. Perhaps other implementations of the C++ standard library perform better. [0] https://stackoverflow.com/a/70587711/ https://stackoverflow.com/a/70587711/
- steveklabnik 2y agoIn my understanding, other implementations cannot perform better, because the root cause is how it is defined in the standard. Basically, any better implementation would be non-conforming. It’s not the kind of ABI issue where simply choosing a different one would help; the flaw comes directly from the definition, which cannot be changed. Of course, non-std implementations of regexes in C++ don’t have this issue. Were strictly talking about the standard library one.