Performance analysis and optimization