All this happens in a fraction of time, which is why phase detection system is much faster than contrast detection system (which relies on changing focus back and forth until focus is achieved, with lots of image data analysis happening on the image sensor level).