Describe a time you had to optimize a piece of code that was causing performance bottlenecks in a production system.