From the course: Refactoring with GitHub Copilot

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Refactoring for performance

Refactoring for performance

By now you've probably noticed a pattern; identify an issue in code and ask Copilot about it. Here's a check for duplicates in an array. It's a slow implementation. It iterates over the array, and during each step, iterates over all items to see if there's a match. On line 6, the second part of the condition is iterating the list of duplicates. So this just won't scale. All right, Copilot, let us know what you think. Improve performance. Of course, Copilot is not only going to give me an improved algorithm, it's also going to explain why. If you aren't familiar, a set stores unique values. So the collection will grow slower in cases of the original array has lots of duplicate items. As you can see, this has turned into one for loop rather than two. Also, with that duplicates.include call. So that's all well and good. But this refactoring is very specific to the example implementation. What can we do about application-level performance? Well, one of the first things we do in web…

Contents