Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 321892

Summary: [Performance] findFilesForLocation interacts badly with linked resources
Product: [Eclipse Project] Platform Reporter: James Blackburn <jamesblackburn+eclipse>
Component: ResourcesAssignee: Serge Beauchamp <serge>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jamesblackburn+eclipse, john.arthorne, kirk.beitz, serge, yevshif
Version: 3.6Flags: john.arthorne: review+
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Bug Depends on:    
Bug Blocks: 318410    
Attachments:
Description Flags
backtraces.tar.bz2
none
Fix none

Description James Blackburn CLA 2010-08-05 11:14:27 EDT
Created attachment 175953 [details]
backtraces.tar.bz2

CDT performs a lot of location -> resource mapping. It does this before a build during dependency calculation.  It appears that this is very expensive when the project contains links due to non-optimal re-calculation / resolution of the linked resource roots.

For every location to search, FileSystemResourceManager#allPathsForLocationNonCanonical, iterates over every link in every project, resolving it to an URI. It then checks whether the location is relative to the URI.

This seems to be very expensive -- can it be cached?

In the attach tar.bz2 you can see we got a VM backtrace every 1-2 seconds.  30s or so was spent resolving dependencies using findFilesForLocation.  

Almost every backtraces was in:
ProjectPathVariableManager.resolveURI(ProjectPathVariableManager.java:286)

I'll try to add some better intelligence to the CDT end, but if this is very poorly performant, can a cache be added to the ProjectPathVariableManager?
Comment 1 Serge Beauchamp CLA 2010-08-05 15:56:28 EDT
Yes, we've run into that same problem, I think there's some lookup that the core.resources plugin should be able to do with the AliasManager.

I'll look into it.
Comment 2 Serge Beauchamp CLA 2010-08-12 10:34:14 EDT
Created attachment 176470 [details]
Fix

Here's a fix for the find[Files | Containers]ForLocation[URI] methods so that the AliasManager is used.

It improves the performance of those methods by several order of magnitude, basically transforming the algorithm into a simple lookup in a Hashtable where before it had to iterate through every single linked resource in the workspace (and resolve every single one).

In my example, it improved the performance so a single call went from 3400 ms to 8 ms.

There's still an edge case where if the user has an custom EFS project that contains linked resources, the performance optimization won't apply, since the AliasManager won't help resolving the file store with the custom scheme.  

In the overwhelming number of use-cases, though, it will apply.
Comment 3 Serge Beauchamp CLA 2010-08-12 10:39:44 EDT
John, can you review it please?
Comment 4 John Arthorne CLA 2010-08-20 12:18:50 EDT
(In reply to comment #3)
> John, can you review it please?

This fix looks good to me. Feel free to release. I guess this was unlikely to be a problem in that past since links had to be created manually so they typically didn't appear in large numbers. Today, it is easy for a user to quickly create hundreds of links, so this kind of bottleneck easily comes up and is worth optimizing.
Comment 5 Serge Beauchamp CLA 2010-08-20 16:11:06 EDT
Thanks John, now fixed on head.
Comment 6 Kirk Beitz CLA 2010-10-07 01:32:20 EDT
*** Bug 323465 has been marked as a duplicate of this bug. ***