How does the Swift compiler optimize performance, and what is the difference between static and dynamic dispatch?