If you are interested, you might like to gather all information about code optimisation in a single thread.
From what I've seen, FPC is actually not very clever in discarding useless code, so it makes sense to apply some rules to avoid generating useless assembly code lines.
For example, when beginning with Ultibo/FPC, I figured out that multiple setLength commands on a dynamic array was very time consuming (no surprise), so I was making intermediate calculations to use SetLength as little as possible.
So I would do things like:
Code: Select all
myArray: array of byte;
myLength += Length(myString);
myLength += 3 + 2 + 1; //Thinking the compiler would optimise this.
From checking the generated assembly code, I found out that "myLength += 3 + 2 + 1;" is generating more code than "myLength += 6;", which means that FPC is not too inclined in performance optimisation...
Fortunately, this situation is easily survivable, it is usually just a matter of having an idea of what assembly code the compiler will generate behind.
I will post in this thread my future findings.