News for hackers. Stuff that matters.
Re:I stopped everything and started writing C again by MaxBarraclough on Thursday March 13, 2025 @04:08PM (#43356800)
What's slow about regex? A properly optimised regex engine ought to be very efficient (if used sensibly, at least).
Re:I stopped everything and started writing C again by steveklabnik on Thursday March 13, 2025 @04:48PM (#43357094)
std::regex in C++ cannot be "properly optimized" due to various factors: https://stackoverflow.com/questions/70583395/why-is-stdregex...
Re:I stopped everything and started writing C again by MaxBarraclough on Thursday March 13, 2025 @05:07PM (#43357239)
The 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/

Re:I stopped everything and started writing C again by steveklabnik on Thursday March 13, 2025 @06:16PM (#43357758)
In 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.