Advancing the timing does mean beginning the burn before TDC. So by the time the piston is passing TDC the majority of fuel is burning.
It isn't as if all the fuel explodes in an instant. One of the most important aspects in engine design is the burn pattern. Air and fuel are still being introduced to the chamber when ignition begins and the way it swirls determines the rate and efficiency of the burn. Higher octanes burn slower and thus ignition can begin earlier. This allows more of the fuel to burn, thus increasing power and MPGs.
Anyway, with direct injection, the computer controls when and how much fuel is introduced along with the spark timing. Thus detonation can be avoided by delaying the introduction of fuel. But this means there is less time to add fuel and still expect it to burn effectively. Resulting in lower power and lower MPGs.
The main way to control the burn and the way the air/fuel moves involves the shape and length of the intake and exhaust ports, the placement and size of the valves, the rate and height and time at which valves open and close, the size and shape of the combustion chamber, etc.
And that is a simple explanation
As you can see, it is quite involved and it used to be all trial and error. With the advent of super computers and dynamic equations much of the guess work can be avoided, but it still comes down to building and testing, tweaking, repeating.
Of course, cost and reliability are always factors affecting the final product. There comes a point of return on investment. The masses do not want to spend another $1,000 on a car for 0.1 more MPG or 1 more HP.