2 ms·
C++ is (according to Bjarne Stroustrup) a general purpose programming language that can be used to build general business software and applications with, not ju
by xmcqdpt2 2y ago
C++ is (according to Bjarne Stroustrup) a general purpose programming language that can be used to build general business software and applications with, not just a systems PL. This is why perf is all over the place —- the core language is fast like C but the stdlib contains terribly slow code (regex, exceptions) and ways to waste lots of cycles (wrapping everything in smart pointers, using std::map instead of unordered map).
- MaxBarraclough 2y agoWhat'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.