Search code examples
eclipseeclipse-cdt

Eclipse indexing - what do the various options do


When you right-click > index on a project there are a few options:

  1. Rebuild
  2. Freshen All Files
  3. Update with Modified Files
  4. Re-resolve Unresolved Includes

I've been just hitting rebuild everytime but now I'm working on a huge project and can't afford to do that; when I modify a file, whether it's a .cpp or .h, I need to know which 'index' operation to do.

For each of the 'index' options:

  1. What does it precisely do?
  2. What is the cost (relative memory, CPU time)?

Documentation from Eclipse would be helpful but already searched and didn't find any.


Solution

  • Rebuild can only be performed on the whole project. It throws away the project's entire index and rebuilds it from scratch, indexing each file in the project.

    Since it starts by throwing away the previous index, cancelling a Rebuild will result in an empty or partially built index.


    The other actions can be performed either on the whole project, or on a folder or file (or group of folders/files) in the project.

    They all go through the files in the selection, and update some or all of them in the index. Unlike Rebuild, they do not start by clearing the index, so cancelling them is relatively safe.

    Freshen All Files updates all files in the selection. If called on the project, the end result is comparable to Rebuild.

    Update with Modified Files only updates those files in the selection which have changed since the last time they were updated in the index, as determined by their timestamp and a hash of their contents.

    Re-Resolve Unresolved Includes only updates those files in the selection for which configuration info (such as specified include paths) has changed, and the change resulted in an include that was previously unresolved now being resolved.


    The performance characteristics can vary a lot depending on the project size and the kind of machine you're running on. I work on a very large project (millions of lines) for which a Rebuild can take 20-30 minutes on a relatively modern desktop. The operation is typically CPU-bound, but the indexer is currently single-threaded, so it will only use up one CPU core.


    Finally, I'd like to mention again what I said in my comment on the question: if you configure the index to be updated automatically in Preferences | C/C++ | Indexer, you shouldn't need to manually invoke these commands at all, at least in theory. In practice, I find an occasional Rebuild is necessary (say once every few weeks), especially after a configuration change (e.g. adding a new include path).


    Sources: this mailing list post, reading the implementation of the actions, and experience using CDT.