Skip to content
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

Code Health: Optimize C++ Code for performance #6368

Closed
WSLUser opened this issue Jun 5, 2020 · 4 comments
Closed

Code Health: Optimize C++ Code for performance #6368

WSLUser opened this issue Jun 5, 2020 · 4 comments
Labels
Issue-Question For questions or discussion Needs-Tag-Fix Doesn't match tag requirements Resolution-Answered Related to questions that have been answered

Comments

@WSLUser
Copy link
Contributor

WSLUser commented Jun 5, 2020

Description of the new feature/enhancement

As discussed in #6350, we do not appear to be optimizing our C++ code to run faster I/O (while still maintaining safety). We should optimize code using iostream and other related header libraries but preferably with fast_io, which is fastest currently in existence, which aims to become part of the C++20 standard. https://www.thegeekstuff.com/2015/01/c-cpp-code-optimization/ is a general guide on how to optimize our code. https://github.com/expnkx/fast_io/wiki provides specific examples for different types of operations that can be optimized using fast_io.

Proposed technical implementation details (optional)

Start by merging adding #5152 and #5080 but those will provide only small benefit. Otherwise use the fast_io wiki to help optimize code as PRs are created if relevant to the PR. Depends on: #6350 being implemented.

@WSLUser WSLUser added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Jun 5, 2020
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jun 5, 2020
@WSLUser WSLUser changed the title Optimize C++ Code for performance Code Health: Optimize C++ Code for performance Jun 5, 2020
@beviu
Copy link
Contributor

beviu commented Jun 5, 2020

I'm pretty sure that most points on that article (1, 2, 4, 5, 6, 7 and 10) are wrong because the compiler can already do them automatically.
There is a website to check what assembly the compiler generates: https://godbolt.org/
For example, if we try with the first example on that article and turn optimization on, then we get the same result for the "slower" code than the "faster" code: https://godbolt.org/z/T5fM5y (EDIT: wrong link) (I've modified it a little bit to remove useless code).
Note that I'm not a pro at c++.

@WSLUser
Copy link
Contributor Author

WSLUser commented Jun 5, 2020

It's also from 2015 so I wouldn't be surprised if some things changed. It's good the compiler can do some stuff for us but we eventually want to be cross-platform. It might be better to be explicit so we don't have to rely on the compiler. Regardless, using fast_io will still be better than any compiler optimizations (at least until it's included like fmt is into the standard).

@DHowett
Copy link
Member

DHowett commented Jun 5, 2020

Thanks for filing this! I'd prefer to keep track of performance issues at a finer scale than this, however. Performance informs everything we do, and I'm not ready to declare a flag day where the five of us sit down and pore over perf traces and rewrite large swaths of code based on those numbers.

When we find hot spots, we'll file them. When we don't find hot spots, we look for better and better corpuses of data so that we can find hot spots. Only from there can we file workitems to drive those hot spots back down. 😄

Closing for now, but I'd like to retain this as a discussion issue.

@DHowett DHowett closed this as completed Jun 5, 2020
@DHowett DHowett added Issue-Question For questions or discussion Resolution-Answered Related to questions that have been answered and removed Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jun 5, 2020
@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label Jun 5, 2020
@WSLUser
Copy link
Contributor Author

WSLUser commented Jun 5, 2020

I was thinking of this as a master issue from which, we could file smaller issues as you've said that are tracked here. When I have some time, I'll be looking for a spot where I can introduce some optimized code using fast_io and bring the dep in with that as an example where we could use it. Of course somebody else can beat me to it and that won't bother me at all. Best place I can think of currently is where we actually have used fmt, which should provide some gain though not as much as somewhere in the code that hasn't been optimized at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question For questions or discussion Needs-Tag-Fix Doesn't match tag requirements Resolution-Answered Related to questions that have been answered
Projects
None yet
Development

No branches or pull requests

3 participants