
Visual C++ Compiler Optimizations (2015) - cgopalan
https://msdn.microsoft.com/en-us/magazine/dn904673.aspx
======
munchbunny
This brings up an important piece of wisdom I see frequently stated and
frequently ignored: don't micro-optimize until you've measured that you need
to.

There are obviously exceptions in specific domains, but even in high
performance cases it is generally better to optimize once you know where the
bottlenecks are in practice.

~~~
ska
You can pretty much just drop that "micro-". With very few exceptions, you
really shouldn't optimize until you have accurate measurements of what is
going on.

Update: To me, a lot of responses here conflate "optimization" with "design".
From where I'm sitting, "optimization" means making adjustments to and
existing solution to make it faster. That has nothing to do with choosing an
appropriate language or toolset, and limited amounts to do with overall
design. Yes, sometimes you must project forward a bit, for example knowing
you'll be able to optimize out exponential behavior with a better data
structure, say.

But often people do too much, too early, with too little information.

~~~
jules
The qualifier "micro-" is right. You have to pick the language, and design
your data structures and algorithms for efficiency from the ground up. Doing
that after the fact is a nightmare, and downright impossible if you made the
wrong language choice.

~~~
ska
That isn't what "micro-" typically means in this context. You are talking
about design.

real micro optimization examples: order of operation in an inner loop.
Changing memory alignment to facilitate vectorization, figuring out your
compiler is doing something dumb and tricking it into better code generation
for that area,etc.

If you are looking at generated assembly, chances you are doing micro-
optimization.

~~~
jules
I may have expressed myself in a confusing way, but it was in fact my
intention to express that while you don't need to worry about micro-
optimization up front, you _do_ need to worry about designing for efficiency
up front.

~~~
ska
Absolutely agreed - just don't think that describes optimization, and my
comment was about optimization.

------
melted
I'd rather they worked on improving IDE support for Clang and LLVM when it
comes to "unmanaged" languages, as well as moved some of those compiler and
optimization engineers to improving LLVM. LLVM still lags a bit behind GCC
when it comes to performance of the machine code it generates, so I'm sure
improvements there would be quite welcome, and I'm also sure Microsoft has the
expertise to make it happen. For extra brownie points, help the community
implement a portable debugger that doesn't suck, because thus far all attempts
at this have failed miserably.

Microsoft C++ compiler is a source of aggravation at best. Their unmanaged
language tooling has been neglected for nearly a decade while FOSS community
(led by none other than Apple) plowed ahead and delivered the work of art that
is Clang/LLVM, and a profusion of languages like Rust and Swift that run on
top of that infrastructure.

~~~
mpinteractiv
Unfortunatly LLVM/CLang is a second citizen on Windows. It's tough to use
anything that depends on it.

~~~
melted
And that's exactly my point. It doesn't have to be this way.

------
waynecochran
> And sqrt is called only once before the loop starts.

Umm.. it should be evaluated at the top of the loop each time.

~~~
giancarlostoro
The value of x doesn't change so calling sqrt once and re-using that value is
a quicker approach I would think.

