Memory and performance debugging
Send the suspect code with the monitoring data, and have GPT-6 Sol say why the resource only ever grows, give the fix, and name the metric to watch after deploy. Run the change in staging for a while first.
Example: Why does the service’s memory keep growing?
Material
- cache.ts
- const cache = new Map(); export function getUser(id) { if (!cache.has(id)) cache.set(id, loadUser(id)); return cache.get(id); }
- Monitoring
- Over 7 days of uptime, memory rose from 400 MB to 3.1 GB; about 1.2 million distinct users visited.
PromptUsing the code and monitoring data, find why memory keeps growing, give the fix, and say how to confirm it is resolved after deploy.
Sample answer · written by hand to show the reasoning
The cache only ever adds entries and never removes them, so every user who visits stays in the Map for good, and memory grows with the number of users seen. Switch to an LRU cache with a size limit and give each entry an expiry. After deploy, check that memory levels off within a few hours instead of rising with uptime.