Profiling time performance with AI

Advanced AI-Assisted Coding for Developers

Thalia Barrera

AI Engineering Curriculum Manager, DataCamp

What we'll cover

Magnifying glass examining data structures

 

  • Profile code
  • Identify performance bottlenecks
  • Evaluate data structure choices
Advanced AI-Assisted Coding for Developers

Profiling with cProfile

 

profile-inspection-ch1.png

 

What cProfile measures:

  • CPU time per function
  • Functions that are called
  • Number of calls
  • Time per call
Advanced AI-Assisted Coding for Developers

AI interprets the profile

profile-analysis-ch1.png

Advanced AI-Assisted Coding for Developers

Understanding the hotspot

location-transfer-index.png

Advanced AI-Assisted Coding for Developers

Understanding the hotspot

data-structures.png

Advanced AI-Assisted Coding for Developers

Efficiency assessment

data-structures-efficiency.png

 

AI assessment:

  • ✅ Acceptable for low data volumes
  • ❌ Lack optimizations for large-scale performance
Advanced AI-Assisted Coding for Developers

Deep dive: HashMapLinear

 

hashmaplinear-class.png

HashMapLinear Issues

 

HashMapLinear scalability:

  • ✅ Suitable for small, fixed-size maps
  • 📉 Linear time degradation
  • ❌ Problematic when data grows unpredictably
Advanced AI-Assisted Coding for Developers

Concurrency concerns

Thread collision race condition

Thread safety issues:

  • Concurrent reads/writes can race
  • Risk of data corruption
Advanced AI-Assisted Coding for Developers

AI-suggested reimplementation

hashmaplinear-reimplementation-with-prompt.png

 

  • 🔎 Always review AI suggestions
  • 🔎 Test before applying
Advanced AI-Assisted Coding for Developers

Benchmark validation

 

Benchmarking run:

benchmarking-run.png

Results:

  • Original (HashMapOld): baseline
  • Optimized (HashMapNew): 2x+ faster
  • ✅ AI patch validated
Advanced AI-Assisted Coding for Developers

The AI-assisted optimization cycle

 

lesson1-2-review.png

Advanced AI-Assisted Coding for Developers

Key takeaway

 

optimization_cycle_2.png

 

The iterative cycle:

  • Profile the code
  • Identify dominant operations
  • Rewrite where it matters
  • Validate the results

🤖 AI helps us move faster with evidence-based decisions

Advanced AI-Assisted Coding for Developers

Let's practice!

Advanced AI-Assisted Coding for Developers

Preparing Video For Download...