Bug 24758 - Features loaded multiple times during the session
Summary: Features loaded multiple times during the session
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Update (deprecated - use Eclipse>Equinox>p2) (show other bugs)
Version: 2.0   Edit
Hardware: PC All
: P2 major (vote)
Target Milestone: 2.0.2   Edit
Assignee: Christophe Elek CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-14 13:14 EDT by Dejan Glozic CLA
Modified: 2002-10-17 16:48 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dejan Glozic CLA 2002-10-14 13:14:39 EDT
Based on the spec, a feature is unique within  site. In other words, there 
exists only one feature with a particular id/version combination within a site.

Based on this constraint, the caching mechanism implemented by FeatureReference 
is wasteful because multiple feature references can point at the same feature 
but are not aware of it and will cache multiple copies of the same feature (see 
tracing below).

We need to modify caching by moving it to the site object. Feature references 
should pass the ID/version combination to the site object and ask for a feature 
object. Sites should create these objects if not found, then cache them in a 
hash table using id_version for a key. This is to avoid that feature references 
hang onto their own copy of a feature.

Here is an example printed from FeatureReference.createFeature method. During 
the navigation throught the Configuration view in the Update Manager, the same 
features (id_version) are created several times by the corresponding feature 
reference. This affects performance and increases in-memory footprint.

Tracing:

Created feature: com.example.bogus_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.0.e388 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.e388_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.e452_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.root_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.root_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyzbogus_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyzbogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.pde_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.sdk.win32_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.0.e388 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.e388_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyzbogus_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.root_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyzbogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.pde_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.sdk.win32_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyzbogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.pde_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.0.e388 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.0 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyzbogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.pde_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.jdt_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.win32_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform.source_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: org.eclipse.platform_2.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.bogus_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Created feature: com.example.xyz_1.0.1 in site 
file:d:/eclipse201/eclipse/update-area/
Comment 1 Dejan Glozic CLA 2002-10-14 14:08:11 EDT
Conditional 2.0.2 (if we are done with all other defects and are on time).

Proposed implementation:

Add a method to ISite interface:
/**
 * Creates a new feature object. The feature must exist on this site
 * or a core exception will be thrown. Concrete implementations 
 * may elect to cache instances, in which case subsequent calls 
 * to create a feature with the same type, version and id will
 * return the same instance.
 * param vid versioned identifier of the feature to create
 * param type the feature type that will be used to select the factory. If
 * <code>null</code> is passed, default feature type will be used.
 * param url URL of the feature archive as listed in the site.
 * return newly created feature object, or a cached value if
 * caching is implemented by this site.
 */

IFeature createFeature(VersionedIdentifier vid, String type, URL url) throws 
CoreException;

Possible implementation in 'Site':

public IFeature createFeature(VersionedIdentifier vid, String type, URL url)
throws CoreException {
   // First check the cache
   IFeature feature = (IFeature)featureCache.get(vid);
   if (feature!=null) return feature;
   // Create a new one
   if (type == null || type.equals("")) { //$NON-NLS-1$
	// ask the Site for the default type 
	type = getDefaultPackagedFeatureType();
   }
   IFeatureFactory factory = FeatureTypeFactory.getInstance().getFactory(type);
   feature = factory.createFeature(url, this);
   if (feature != null) {
	VersionedIdentifier featureID = feature.getVersionedIdentifier();
        if (vid.equals(featureID)==false) {
           // FIXME: non-NL message
	   UpdateManagerPlugin.warn("The versionId of the referenced feature  
doesn't match the one of the feature reference:" + getURL());
	}
        // Add the feature to the cache
        featureCache.put(featureID, feature);
   }
   return feature;
}
Comment 2 Dejan Glozic CLA 2002-10-14 14:10:43 EDT
The new site method should be called from FeatureReference.getFeature
(IFeatureReference) 
Comment 3 Dejan Glozic CLA 2002-10-14 14:15:39 EDT
In this light (since caching already exists on a site), feature reference may 
drop its own cached IFeature hadles and always call ISite. The performance loss 
will be miniscule because the call will immediately return cached IFeature 
instance if it has already been created. This can at least be done for 'exact' 
match. For 'best' match, we may still choose to hang on the feature because 
some lookup is involved.
Comment 4 Dejan Glozic CLA 2002-10-17 16:48:49 EDT
Fixed and tested.