Hacker News new | ask | show | jobs
by otabdeveloper4 1083 days ago
There's nothing wrong with the std::regex design as it is the standard.

std::regex only sucks because the developers of gcc and clang never bothered to optimize it. (Too much work and they have other stuff to worry about.)

2 comments

"can't be fixed without breaking ABI" sounds plausible for C++.

There's generally not all that much stdc++ specific optimisation stuff in clang. There might be parts of regex that are worth implementing as compiler intrinsics, that seems to be the existing pattern for making bits much faster.

The really heavy lifting you want for regex is to partially evaluate and split them. They're a separate language unto themselves and benefit from being optimised as such. There's nowhere ideal in the clang/llvm pipeline to do that though.

C++ regexes are literally just copy-pasted ECMAScript regexes. They could have just used an existing regex library, but C++ compiler developers presumably don't want to support an extra dependency.

That's the only real reason why std::regex is slow.

std::regex also depends on locale, which is reason enough to avoid it, regardless of performance.