Explain how you would profile and optimize a piece of Python code that is running too slowly for real-time inference in an ASML pipeline.