EMF Model Loading Performance Tweaks (Deprecated)

Aus SDQ-Wiki

Problem: Poor model loading performance for large models in Eclipse EMF (Deprecated)

Solution: Set optimised Hashmaps for model loading / references. Find the MyModelResouceImpl classes in the generated code in the util packages and add setIntrinsicIDToEObjectMap to the MyModelResourceImpl constructor. The solution proposed below does not require specific maps with load option to be set when loading a model; instead the intrisic IDs will be automatically used each time the model loading is triggered.


public class MyModelResourceImpl extends XMIResourceImpl {
	// ...

	 * Creates an instance of the resource.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @param uri the URI of the new resource.
	 * @generated NOT //SET!
	public MyModelResourceImpl(URI uri) {
		this.setIntrinsicIDToEObjectMap(new HashMap<String, EObject>()); // add this line

Do not forget to set generated to NOT, otherwise the changes will be overwritten on next re-generation.

Default EMF Load Options (Deprecated)

resource = editingDomain.getResourceSet().createResource(resourceURI);

Map loadOptions = ((XMLResourceImpl)resource).getDefaultLoadOptions();
loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl());
loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap());

((ResourceImpl)resource).setIntrinsicIDToEObjectMap(new HashMap());

try {
} catch (IOException e) {

Problem: Model loading performance problems with referencing models (Deprecated)

If EMF models reference each other, one can experience problems with loading a model which links other models. For example Model A references Model B and C. When loading Model A, the performance is low. EMF over and over again tries to resolve elements from B and C for every proxy model element of A.

Solution: Explicitly load the referenced models before loading the referencing model into the same ResourceSet. In the example: Manually load B and C before loading A; do not rely on the automatic resolve of proxies.


Keywords: EMF, performance, loading, load, model, references, proxy, linked model, large model, big model