Question: When you know that your software (not a driver, not part of the os, just an application) will run mostly in a virtualized environment are there strategies to optimize your code and/or compiler settings? Or any guides for what you should and shouldn't do?

This is not about a 0.0x% performance gain but maybe, just maybe there are simple things that will improve performance drastically or things that seem simple but are known to be disastrous in virtualized environments. For example enabling CONFIG\_PARAVIRT in a kernel build is easily done and can boost performance a lot. Now I'm looking for similar things for applications, if there are any. 

In my case it will be C++ Code and probably VMWare but I want to keep the question as language/product-agnostic as possible. I wonder if there even are such strategies or if this would be a complete waste of time - after all the concept of virtualization is that you don't have to care too much about it.

Answer: 
I've found it to be all about I/O.

VMs typically suck incredibly badly at IO. This makes various things much worse than they would be on real tin.

Swapping is especially a bad killer - it completely wrecks VM performance, even a little, as IO is so slow. 

Most implementations have a large amount of IO contention between VMs, I've not seen one which avoids this or handles it sensibly.

So use a ramdisc for temporary files if you can, but don't cause it to swap, because that would be even worse.
The things that are slow on real hardware are even slower when the system is virtualized. It depends on the virtualization technology being used how much slower they become.

Especially avoid anything that requires I/O with the world outside the virtual environment. Depeding on how things are set up, this includes drawing on the screen, swapping, and disk and network I/O. That's roughly in a decreasing order of importance.

If possible, pretend you're writing for a ten-year-old computer. If your application would work on a 1999 desktop PC, or laptop, it should do OK.