Performance optimization with GitHub Copilot

Software Development with GitHub Copilot

Thalia Barrera

AI Engineering Curriculum Manager, DataCamp

The silent slowdown

 

nanobanana: half: A split illustration contrasting a fast responsive application shown as a smooth rocket launching on one side and a slow spinning loading indicator on the other, flat vector style

 

Performance issues:

  • Don't show up in unit tests
  • Don't cause immediate crashes

 

📈 Code looks correct, but doesn't scale

Software Development with GitHub Copilot

A bottleneck in the wild

 

def find_common(list1, list2):
    common = []
    for item in list1:
        for item2 in list2:
            if item == item2:
                common.append(item)
    return common

 

  • Code works fine for small inputs
  • 1 million items → 1 trillion comparisons
  • $O(n^2)$ algorithm!

 

❌ Brings down production on a busy day

Software Development with GitHub Copilot

[screencast]

Software Development with GitHub Copilot

[screencast]

Software Development with GitHub Copilot

Tell Copilot what to optimize for

nanobanana: half: A performance dashboard with speedometer dials and metric gauges showing different optimization indicators, flat vector illustration on a clean background

 

  • Speed → faster algorithms, caching, batching
  • Memory → resource cleanup, streaming, generators
  • Both → full performance review
Software Development with GitHub Copilot

Performance prompts that work

 

Targeted optimization

Optimize #selection for performance and reduce time complexity

Review #selection for memory leaks

 

Codebase-wide scan

@workspace find functions with nested loops over large collections

Software Development with GitHub Copilot

[screencast]

Software Development with GitHub Copilot

[screencast]

Software Development with GitHub Copilot

Bake performance into every suggestion

 

.github/copilot-instructions.md

## Performance standards
- Prefer set or dict lookups over nested loops
- Use context managers for files, connections, and sockets
- Avoid loading entire datasets into memory, use generators or streaming

✅ Prevents performance bottlenecks from being written in the code

Software Development with GitHub Copilot

Let's practice!

Software Development with GitHub Copilot

Preparing Video For Download...