Home / Blog / I Deleted 70,000 Lines of Code and My AI Code Edit...

I Deleted 70,000 Lines of Code and My AI Code Editor Got Slower. Here's Why.

By CaelLee | | 7 min read

I Deleted 70,000 Lines of Code and My AI Code Editor Got Slower. Here's Why.

Last week our team did a massive refactor. We slashed our codebase from 150,000 lines down to 80,000. Clean, elegant, beautiful. I felt like Marie Kondo for code—if it didn't spark joy, it got deleted.

Then Cursor's index got 40% slower.

I was genuinely confused. We removed half the code. How does less code make things slower? It took me two days of debugging to figure out what was happening. The culprit? Cursor's Background Agent and its "incremental" update strategy—which, plot twist, wasn't actually incremental at all. It had been running full scans the entire time and lying to me about it for two months.

Let me explain what's going on under the hood, because this probably affects your project too.

What the Background Agent Is Actually Doing

Here's something most developers don't think about. Cursor's Background Agent isn't just a fancy file watcher. It builds and maintains a semantic index of your codebase, and that index has three main components:

Every time you save a file, the Agent triggers what's supposed to be an incremental update. In theory, it should only re-analyze the changed parts and merge the results into the existing index.

In practice though? That "incremental" update has a nasty habit of turning into a full rebuild.

That's exactly what happened to us. After the refactor, our file count dropped from 400+ to about 200. Looks cleaner, right? But the average file size jumped from 375 lines to 400, and the cross-file dependencies got way more tangled. When the dependency graph changes beyond a certain threshold, the Background Agent's incremental algorithm just... gives up. It falls back to a full index rebuild.

What threshold? I dug through Cursor's logs and compared notes with a few folks on Reddit and Discord. From what we can tell, if a single change affects more than 15% of the dependency nodes, it triggers a full re-index. Our refactor touched 60% of the modules. The Agent didn't stand a chance.

Three Strategies That Actually Fixed Our Index Speed

1. Control Your Dependency "Fan-Out"

The first mistake we made was over-abstracting. During the refactor, we extracted a ton of utility functions and base classes, and our dependency graph turned into a fan—one low-level module referenced by 50+ files.

Here's a concrete example. We had a single formatDate utility function used by 47 different components. Every time we modified that function, the Background Agent had to re-analyze the type inference paths across all 47 files. We eventually split it into three more specific functions: formatDisplayDate, formatAPIDate, and formatRelativeTime. Each one is now referenced by 10-15 files.

The result? Index update time dropped from 8 seconds to 2 seconds.

Wait—I should clarify something. That 8-to-2 second improvement is for incremental updates, not full index rebuilds. Full rebuilds still take 30+ seconds. There's no getting around that. Don't be misled.

After reducing the average fan-out from 23 dependents to 8, our incremental index success rate jumped from 60% to 92%. By "success rate," I mean actual incremental updates versus total triggers. The remaining 8% still degrade to full scans, but that's dramatically better than before.

2. Use `.cursorignore` to Layer Your Index

Everyone knows .gitignore, but I'm constantly surprised by how many developers don't realize Cursor supports .cursorignore. I discovered this feature in Cursor 0.42 back in November 2024—it was literally a one-line mention in the changelog. Almost missed it entirely.

This file gives you granular control over what gets indexed. Here's how I layer things:

Real-world case: we have a legacy-admin directory with 30,000 lines of old backend system code that nobody touches. It was adding about 12 seconds to every global index. After adding it to .cursorignore and marking key files with # cursor-index: skip, indexing dropped to 4 seconds. When we need to work on the legacy code, we just temporarily remove the ignore rules.

There's a gotcha here though, and it burned me hard. Don't blindly ignore node_modules wholesale. I did that at first—seemed logical—and my code completions immediately went to garbage.

Why? Because Cursor needs to index the type definitions for libraries you actually import. My solution:


# Ignore source, keep type definitions
node_modules/**/*.js
node_modules/**/*.ts
!node_modules/**/*.d.ts

3. Manually Trigger Index Checkpoints

The Background Agent's async mechanism has this annoying problem—it doesn't know when you've "finished writing a logical chunk." Every save triggers an incremental update. Save 10 times in a row, and it queues up 10 updates, with later tasks frequently failing because of inconsistent dependency states.

Honestly, this design baffles me. Someone filed a GitHub Issue about it in January 2025, and it got over 200 comments. As of today, Cursor still hasn't addressed it.

My workaround: use Cursor's Index: Create Checkpoint command to manually mark checkpoints. Hit Cmd+Shift+P and search for it. Here's my current workflow:

After adjusting the debounce time, our team's daily index failure retries dropped from an average of 340 to about 80. Peak CPU usage also went from 65% down to 35%. I pulled these metrics from Cursor's developer tools—more on that in a bit.

The Dumbest Thing I Did While Debugging This

OK, funny story. For about a week, I thought Cursor's completions were getting sluggish. I assumed it was an indexing problem, so I rebuilt indexes, tweaked parameters, pulled my hair out. I spent hours on this.

The culprit? I had 80 Chrome tabs open, my memory was at 95% utilization, and the system was swapping like crazy. Cursor's Background Agent and Chrome were fighting over resources, and Chrome was winning.

This happened in December 2024. I remember it vividly because it was Christmas Day. I was at home debugging this ridiculous problem while my girlfriend watched some Netflix drama in the background, and I'm sitting there cursing at my laptop.

Lesson learned: before you go deep on index performance, check your system resources. The Background Agent is both I/O and CPU-intensive. If you've got less than 4GB of free RAM, incremental updates will almost certainly fail. Our standard dev machines now have 32GB of memory, with 8GB reserved for Cursor. The company-issued M3 Pro MacBooks with 18GB? Those struggle with medium-sized projects, honestly.

How to Know If Your Index Strategy Is Healthy

I track three metrics in Cursor's developer tools. Open them via Help > Toggle Developer Tools and look at the Console for [BackgroundIndex] logs:

  1. Incremental update success rate > 85%: Below this number, something's wrong with your code structure or configuration
  2. Single index time < 5 seconds: Anything longer and you'll feel the lag in your coding flow. I personally prefer under 3 seconds, but 5 is acceptable
  3. Index queue length < 3: If you regularly see more than 5 tasks queued up, your debounce settings need adjustment

Our team now spends 10 minutes every Friday afternoon reviewing these metrics. We catch problems 2-3 days before anyone actually notices them. I picked up this habit from a former Google colleague—apparently they do the same thing internally for their build systems.

Key Takeaways

Here's what I want you to remember:

I've started treating index configuration as part of our engineering standards, right alongside ESLint rules and CI pipelines. New team members get an "Index Optimization Checklist" in their first week. It looks something like: check dependency fan-out, configure .cursorignore layers, adjust debounce timing, set up memory monitoring.

What's Your Experience?

What's your Cursor index speed like? Have you ever had completions lagging but couldn't figure out why? Drop a comment—I'll try to help you diagnose it. From what I've seen, most teams don't realize this is even a problem until the indexing gets so slow it's actively hurting productivity. By then, you're already playing catch-up.

cursor #developer-tools #performance #engineering #vscode

C

Cael Lee

Full-stack developer with 8+ years of experience. Currently building AI-powered developer tools. I've tested 20+ AI API providers and coding assistants.

Ready to get started?

Get your API key and start building with 180+ AI models.

Get API Key Free