This is what I am going to use for copilot-instructions.md for GitHub Copilot.
# Copilot Instructions for Debugging Memory Issues
This is a Next.js full stack web application using ES Modules (ESM) various tools and libraries. Follow these steps to debug the app for excessive memory usage, memory leaks, and improper transaction handling.
## Steps to Debug Memory Issues
1. **Monitor Memory Usage in Development:**
- Use the `useMemoryMonitor` hook from [`lib/memoryManagement.ts`](lib/memoryManagement.ts) in your components to monitor client-side memory usage.
- Example:
```typescript
import { useMemoryMonitor } from '../lib/memoryManagement';
export default function MyComponent() {
useMemoryMonitor('MyComponent');
return <div>My Component</div>;
}
```
2. **Check for Unoptimized Images:**
- Use the [useImageOptimizationCheck](http://_vscodecontentref_/0) hook from [memoryManagement.ts](http://_vscodecontentref_/1) to identify unoptimized images that may cause excessive memory usage.
- Example:
```typescript
import { useImageOptimizationCheck } from '../lib/memoryManagement';
export default function MyComponent() {
useImageOptimizationCheck();
return <div>My Component</div>;
}
```
3. **Log Memory Usage in API Routes:**
- Use the [withMemoryMonitoring](http://_vscodecontentref_/2) middleware from [memoryManagement.ts](http://_vscodecontentref_/3) in your API routes to log memory usage.
- Example:
```typescript
import { withMemoryMonitoring } from '../lib/memoryManagement';
const handler: NextApiHandler = async (req, res) => {
// Your API logic here
};
export default withMemoryMonitoring(handler);
```
4. **View Memory Logs:**
- Use the [getMemoryLogs](http://_vscodecontentref_/4) utility from [memoryManagement.ts](http://_vscodecontentref_/5) to view memory logs.
- Example:
```typescript
import { getMemoryLogs } from '../lib/memoryManagement';
const viewLogs = () => {
console.log(getMemoryLogs());
};
```
5. **Analyze Memory Logs:**
- Check the logs generated by [memoryLogger](http://_vscodecontentref_/6) in [memoryManagement.ts](http://_vscodecontentref_/7) for any warnings or errors related to memory usage.
- Logs are stored in `logs/memory.log`.
6. **Handle High Memory Usage:**
- Implement custom logic in [memoryActions.handleHighMemoryUsage](http://_vscodecontentref_/8) in [memoryManagement.ts](http://_vscodecontentref_/9) to handle scenarios where memory usage exceeds a certain threshold.
## Steps to Debug Improper Transaction Handling
1. **Review API Routes:**
- Ensure that all API routes using transactions are properly handling commit and rollback operations.
- Example:
```typescript
const handler: NextApiHandler = async (req, res) => {
const transaction = await startTransaction();
try {
// Your transactional logic here
await transaction.commit();
} catch (error) {
await transaction.rollback();
throw error;
}
};
```
2. **Check for Unhandled Errors:**
- Ensure that all errors are properly caught and handled in both client-side and server-side code to prevent memory leaks and improper transaction handling.
3. **Use Proper Cleanup:**
- Ensure that any resources (e.g., database connections, file handles) are properly cleaned up after use to prevent memory leaks.
Will this work for Cusor “Rules for AI” and if not, how can I optimize it? It is for a specific task where I’m looking to wrap our current code with memory management utilities (for a Next.js app with major memory problems) to assess where problems might be occurring. Thus I’m going to have specific Rules for AI for whatever task I happen to be working on and I’m also wondering if very specific rules like the above are going to enhance the AI capabilities in Shadow Workspace which I turned on.