Opened 12 years ago
Closed 12 years ago
#1680 closed defect (wontfix)
[PATCH] Variables recreation
Reported by: | pragma | Owned by: | |
---|---|---|---|
Priority: | If Time Permits | Milestone: | |
Component: | Core engine | Keywords: | patch |
Cc: | Patch: |
Description
Hello! This is my first try to contribute to open source project, I hope that I didn't made a mistakes.
In many functions I saw that variables created inside loops, and I think need to fix it, because it consumes more memory in stack and also slow down the code (destructor calls etc.)
I am attaching patch as first try, and if you approve it, I will keep to watch sources.
Attachments (1)
Change History (9)
comment:1 by , 12 years ago
by , 12 years ago
Attachment: | small.patch added |
---|
comment:2 by , 12 years ago
Keywords: | patch review added |
---|---|
Milestone: | Backlog → Alpha 12 |
Priority: | Should Have → If Time Permits |
Hmm, any performance benefit would have to be weighed against the disadvantage of making the code more difficult to read. I'm not an expert on compilers, but I'd be surprised if things like this weren't solved by an optimizing compiler. Do you have any evidence that this isn't the case or that this code is particularly important for performance?
comment:3 by , 12 years ago
Also for floats and pointers, I wouldn't expect much benefit to this sort of micro-optimization, but I may be wrong :)
comment:4 by , 12 years ago
Thanks for reviewing! Currently I don't have any evidence, I will try to profile the code. People says that normal compiler can do such optimization, but also advice not to trust too much to compiler.
comment:5 by , 12 years ago
...and I have only changed a few, there are many more similar constructions.
comment:6 by , 12 years ago
C++ by design does not provide default values for built in types. This is so that there isn't a performance cost to declaring a variable (or more noticeably a large array). So the pointers and floats will not have any constructors or destructors.
Optimising compilers do lots of fancy stuff. On a 64 bit machine I would guess that none of those variables you have changed would even touch the stack since the compiler uses registers whenever possible. There is a lot of possible optimisation for the game but this kind of micro optimisation won't help. I did a bit of work on a C++ decompiler recently so have been looking at lots of optimised assembly ;).
The main non-algorithmic performance improvement is gained by improving memory layout.
comment:7 by , 12 years ago
Thanks for your comment, I hurried to make a ticket, because on forums people says the same thing. But: there are also many places in sources where objects with constructors created in loops, and this situation compiler cannot resolve (constructor and destructor will be called anyway). But may be I'm wrong and this creation is necessary. Thanks anyway and good job! I hope the game will run faster on linux soon!
comment:8 by , 12 years ago
Keywords: | review removed |
---|---|
Milestone: | Alpha 12 |
Resolution: | → wontfix |
Status: | new → closed |
I happen to agree with quantumstate on this, so I'm going to close this ticket for now. If you investigate and find there's a significant difference in performance for one of these cases, feel free to reopen the ticket and comment about it.
Getting error 500 when attaching patch