-
Notifications
You must be signed in to change notification settings - Fork 261
perf(io): excise last use of std::regex
#515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Holy carruthers, Batman, that's impressive. Between this and the other regex excision you did yesterday, that's a 95+% speedup in cppfront all-up... simply by not using I am quickly gaining sympathy with the people who've been complaining about regex perf for many years now and recommend against using it. I've never felt the pain because I haven't been a big regex user, and was I trying regex here in cppfront because I felt I should. Now I won't. Thanks. One small fix though: You need to change
to
in two places, because the first is UB (and the Microsoft STL detects it and fires an assertion on it). |
Signed-off-by: Herb Sutter <[email protected]>
Ah, looks like I can just apply the fix right here in the GitHub UI... done. Thanks, Johel! You get the prize for easily the most dramatic performance improvement in cppfront. |
For perspective, I knew compiling the Similarly, I always guessed that regex perf wouldn't be a major factor because cppfront is dominated (I thought) with lots of little heap allocations and also some cache-unfriendly pointer-chasing where I don’t use vectors/deques. Nope, the pointer-chasing is just fine (at least so far). It was regex that totally dominated everything. Which just goes to show again to not trust intuition. As always: Never guess, measure. Incidentally, and pretty remarkably, compiling a file with cppfront is now similar to the speed of doing a file system copy of the file. For example, the second part of my Thanks again. |
That makes sense: https://compiler-explorer.com/z/ffGxxPYTx. |
It occurred to me that this could be refactored to behave like |
No worries, feel free to do a new PR to do it that way instead. |
* perf(io): excise last use of `std::regex` * Change `&*x.end()` to `x.data()+x.length()` to avoid UB Signed-off-by: Herb Sutter <[email protected]> --------- Signed-off-by: Herb Sutter <[email protected]> Co-authored-by: Herb Sutter <[email protected]>
On my system, with a GCC 13 Debug build of Cppfront,
lowering
passthrough-tests/clang-12-libstdc++-e.cpp2
is reduced from 24 s to 0.4 s.
Lowering the other passthrough-tests also takes 0.4 s each.
The passthrough-tests pass, as do the regression-tests: