Some things to note:
- the default for the new compiler is -O 1 (not -O 0 !!!)
- I can hardly imagine any reason (unless we find some bug in the compiler that happens only in -O 2) why anyone would not use always -O 2
Yes, that statement is totally not true, even my app that did compile and run with -l 3 with the old compiler had to be modified. So that is an actual bug in the new compiler if you take that sentence…
Thank you for your detailed response, but I think any response will inexorably entrench us on opposite sides of the debate over the value of Object Oriented program design. And that won…
that's an interesting promo, but it looks like they intentionally didn't include it in the announcement, because I tested: -O2, -O2p -O2z, -O3, -O3p -O3z, and all of them produce the same code/data/..…
BTW previously (maybe in another thread) Jim wrote that if-s are faster than switch cases.
Yeah, if statements save memory compared to switch statements. I think switch statements utilize a jump table which results in bigger code. As far as speed goes, I'd guess that switch statements with lots of cases are faster than the equivalent if..else statements -- O(1) vs O(n) where n is the number of cases -- but for practical purposes nobody is going to notice the speed difference, unless you have 10,000 cases or something.
But in a perfect world, a good optimizing compiler should be able to generate equivalent code for both if you're optimizing for space.
Yeah, but really if you have or want to have enums just try it out and compare in view Memory.
This was just an example. Just would be nice for Garmin to be more clear on what optimizations that make our code harder to read can be stopped without hurting the compiled app. (And also help testing the beta if we find it doesn't do as expected) I expect some optimizations are specific cases so not something we should try to aim our code for, but some may be able to make it so our code can be more readable
I've optimised my code myself so need optimization only for one things that is out of me: putting into code const/enums and not treat them as var (memory/code). When I see the generated code to initialise array with const - shivers go through me :-).
So the most important thing is to explain (it can't be a secret) by example what does it mean (without description I'll spend hours to changing, building and watching into memory monitor):
is 'constant substitution' 'inliniing' values of enums/const?
I've recompiled my WF with beta 4.1.4 and -O 3
1. no const in vars
2. mem usage -2.4kB
3. globals -0,4kB
4. code -1.2kB
5. data -0,5kB
6. entry -0,4kB
7. settings 0kB
Not much (~2% for 92kB devices) but it can save app if you are under the cap
Good work GARMIN!!!!!!!