Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » reduce loading time of an xmi file
reduce loading time of an xmi file [message #1707436] Fri, 04 September 2015 17:17 Go to next message
Ameni BF is currently offline Ameni BFFriend
Messages: 8
Registered: November 2014
Junior Member
Hello,

I want to load an XMI file and get its content. My code works but the loading is taking a lot of time (1hour). I tried to modify the load options but it did not solve the problem.
The code is below:


static EObject loadXMI(String instancePath, EmfModelReader reader)
{

//load model instance
ResourceSetImpl load_resourceSet = new ResourceSetImpl();
load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_DEPRECATED_METHODS, Boolean.TRUE);
load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl());
load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap());
load_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
// reader.getPackages().get(0): returns the EPackage of the core model
load_resourceSet.getPackageRegistry().put(reader.getPackages().get(0).getNsURI(),reader.getPackages().get(0));
Resource load_resource = load_resourceSet.getResource(URI.createURI(instancePath),true);
EList<EObject> elements= load_resource.getContents();
return elements.get(0);
}

Re: reduce loading time of an xmi file [message #1707441 is a reply to message #1707436] Fri, 04 September 2015 17:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Using binary rather than ASCII serialization can give a significant
benefit, but it also inhibits many opportunities to evolve the metamodel.

If you really want to load XMI much faster the following approach is on
my to-do list.

Auto-generate an LPG parser from the metamodel with direct EObject
setXXX action code.

This should replace the generic SAX callbacks by an efficient
metamodel-specific state machine and bypass the many levels of EMF/XMI
flexibility.

If you know that you only want part of the model, a partial load could
be autogenerated as well.

Regards

Ed Willink

On 04/09/2015 18:17, Ameni BF wrote:
> Hello,
>
> I want to load an XMI file and get its content. My code works but the
> loading is taking a lot of time (1hour). I tried to modify the load
> options but it did not solve the problem. The code is below:
>
>
> static EObject loadXMI(String instancePath, EmfModelReader reader) {
>
> //load model instance
> ResourceSetImpl load_resourceSet = new ResourceSetImpl();
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_IDREF_RESOLUTION,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_ATTACHMENT,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_DEPRECATED_METHODS,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_PARSER_POOL,
> new XMLParserPoolImpl());
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP,
> new HashMap());
> load_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
> new XMIResourceFactoryImpl());
> // reader.getPackages().get(0): returns the EPackage of the core model
> load_resourceSet.getPackageRegistry().put(reader.getPackages().get(0).getNsURI(),reader.getPackages().get(0));
>
> Resource load_resource =
> load_resourceSet.getResource(URI.createURI(instancePath),true);
> EList<EObject> elements= load_resource.getContents();
> return elements.get(0);
> }
>
>
Re: reduce loading time of an xmi file [message #1707455 is a reply to message #1707436] Fri, 04 September 2015 19:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
This post is almost devoid of useful information. How big is the XMI
file 2K? 2G? 10G? If it's taking an hour, it's unlikely that XMI is
a good representation for whatever gigantic thing you're loading. If
you want to know why it's taking so long, you'll need to use a profiler...

On 04/09/2015 7:17 PM, Ameni BF wrote:
> Hello,
>
> I want to load an XMI file and get its content. My code works but the
> loading is taking a lot of time (1hour). I tried to modify the load
> options but it did not solve the problem. The code is below:
>
>
> static EObject loadXMI(String instancePath, EmfModelReader reader) {
>
> //load model instance
> ResourceSetImpl load_resourceSet = new ResourceSetImpl();
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_IDREF_RESOLUTION,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_ATTACHMENT,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_DEPRECATED_METHODS,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_PARSER_POOL,
> new XMLParserPoolImpl());
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP,
> new HashMap());
> load_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
> new XMIResourceFactoryImpl());
> // reader.getPackages().get(0): returns the EPackage of the core model
> load_resourceSet.getPackageRegistry().put(reader.getPackages().get(0).getNsURI(),reader.getPackages().get(0));
>
> Resource load_resource =
> load_resourceSet.getResource(URI.createURI(instancePath),true);
> EList<EObject> elements= load_resource.getContents();
> return elements.get(0);
> }
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: reduce loading time of an xmi file [message #1707763 is a reply to message #1707455] Wed, 09 September 2015 08:57 Go to previous messageGo to next message
Ameni BF is currently offline Ameni BFFriend
Messages: 8
Registered: November 2014
Junior Member
Hi,
Thank you for your answers. The size of the Ecore model is 49KB, and the size of the xmi model is 48MB.
Re: reduce loading time of an xmi file [message #1707885 is a reply to message #1707763] Thu, 10 September 2015 08:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
You'll need to measure with a profiler. Something pathological is going
on, but I can't guess what.

On 09/09/2015 10:57 AM, Ameni BF wrote:
> Hi, Thank you for your answers. The size of the Ecore model is 49KB,
> and the size of the xmi model is 48MB.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: reduce loading time of an xmi file [message #1708416 is a reply to message #1707885] Wed, 16 September 2015 11:53 Go to previous messageGo to next message
Ameni BF is currently offline Ameni BFFriend
Messages: 8
Registered: November 2014
Junior Member
Hi,

The solution was to not define any attribute as ID. This reduced the loading time to a few seconds.
Re: reduce loading time of an xmi file [message #1708454 is a reply to message #1707436] Wed, 16 September 2015 16:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Ameni,

Using
org.eclipse.emf.ecore.resource.impl.ResourceImpl.setIntrinsicIDToEObjectMap(Map<String,
EObject>) in the resource factory along with
OPTION_DEFER_IDREF_RESOLUTION (which you're already doing would also
have helped a lot). This way the resource is traversed once, after the
entire resource is loaded, to build an ID to EObject map, which can then
very efficiently resolve each ID.


On 04/09/2015 7:17 PM, Ameni BF wrote:
> Hello,
>
> I want to load an XMI file and get its content. My code works but the
> loading is taking a lot of time (1hour). I tried to modify the load
> options but it did not solve the problem. The code is below:
>
>
> static EObject loadXMI(String instancePath, EmfModelReader reader) {
>
> //load model instance
> ResourceSetImpl load_resourceSet = new ResourceSetImpl();
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_IDREF_RESOLUTION,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_DEFER_ATTACHMENT,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_DEPRECATED_METHODS,
> Boolean.TRUE);
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_PARSER_POOL,
> new XMLParserPoolImpl());
> load_resourceSet.getLoadOptions().put(XMIResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP,
> new HashMap());
> load_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
> new XMIResourceFactoryImpl());
> // reader.getPackages().get(0): returns the EPackage of the core model
> load_resourceSet.getPackageRegistry().put(reader.getPackages().get(0).getNsURI(),reader.getPackages().get(0));
>
> Resource load_resource =
> load_resourceSet.getResource(URI.createURI(instancePath),true);
> EList<EObject> elements= load_resource.getContents();
> return elements.get(0);
> }
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to add ChildDescriptors for EObjects which are in a different Plugins
Next Topic:how to define a source node and a target node in emf
Goto Forum:
  


Current Time: Fri Apr 19 04:16:07 GMT 2024

Powered by FUDForum. Page generated in 0.02383 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top