What is the optimal length of time for pulling a shot of espresso? Assuming:


The beans are ground correctly, and are of good quality
You have the right amount of grind in the basket
The grounds are tamped correctly
The machine is set to the correct temperature (90°C to 96°C (195°F to 205°F))


First: is there an optimal length of time for a shot of espresso to be pulled for highest quality taste and aroma? If so, for how long?
That will completely depend on the blend of espresso you are using.  Different coffees will have different pull times.

In my experience as a barista, you'll aim for about 28 seconds on most shots.  Some of the blends we've used aimed more at 25 to 31 seconds.

TL;DR: Depends on the coffee.