-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Minor improvement [Reserve vector] #1524
Conversation
Save on reallocation cost, by reserving the vector we know the size of before hand.
Thanks for the PR! While you're right, that this improves performance, the code path isn't hot and performance isn't really an issue there. Also calling Python takes the majority of the time anyway. |
This comment was marked as abuse.
This comment was marked as abuse.
It results in the impact of reserve becoming unmeasurable. |
This comment was marked as abuse.
This comment was marked as abuse.
@jhasse I agree this might not be a hot path, that being said this is better code than before, even if it might be on a small magnitude. This is either good (probably is) or does no negative effect at all. I assumed the end goal usually is to achieve for better code. Even if the change is as small as changing a post-inc (i++) to pre-inc(++i), one can make an argument that compilers can optimize that but still you shouldn't compromise on code quality. Anyways, even if this isn't merge I can understand. But could you please update the contribution guide lines to say you guys don't accept minor improvements. |
It hard-codes the number of arguments, so it's not necessarely "better" code. |
Number of arguments, are already hard coded. If you would like to guide me to a better approach, I would be happy to fix this up. |
This comment was marked as abuse.
This comment was marked as abuse.
Thanks, sure i will do that @jonesmz Your fork has ++14!? I thought this repository supported ++11, also I have only used string_view's for C++17 projects, does ++14 support it aswell? |
I meant the number |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
When adding another parameter, one has to remember changing 7 to 8. |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
Exactly ;) There are times when performance is critical and times where developing comfort is more important. For the latter people often choose Python. This shows that this part of Ninja, is not meant to be performance-critical. So "better" code in this case is the one that is simpler, shorter, prettier, etc. IMHO using I think if you would benchmark the change, there wouldn't be a measurable performance impact, making this a case of premature optimization. |
This comment was marked as abuse.
This comment was marked as abuse.
??? This isn't a DM or private chat, I'm replying on the PR.
Sure, but I think that "performance" should be weighted very low for deciding what is an improvement to this code.
His version without the reserve would be even shorter and simpler, so I would prefer that one. Both won't work with C++98, so we can't merge them for now, sorry. |
This comment was marked as abuse.
This comment was marked as abuse.
Nothing. btw: If you add |
This won't be updated here because this is closed, should I make a new PR ? |
This comment was marked as abuse.
This comment was marked as abuse.
Perfect then, because this commit was on the same branch this pull request was made on. |
@jhasse Please guide me with further instructions. |
@shahzadlone The version I prefer requires C++11, so we'll have to wait until Ninja drops C++98 support. |
This comment was marked as abuse.
This comment was marked as abuse.
It's longer and harder to understand IMHO.
No concrete ones. Support for Debian 8 ends on June 30, 2020, that might be a date to keep in mind. |
@jhasse It is better code though, and what is so hard to understand about that code? It also fixes the problem of hard coding things which you yourself pointed out "When adding another parameter, one has to remember changing 7 to 8." |
That's subjective. I think we can agree that good code should be
This is only better on 3. The weighting of those three factors is subjective, I gave some reasoning why I weight performance very low here.
I didn't say it's hard to understand. It's harder. |
Save on reallocation cost, by reserving the vector we know the size of before hand.