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 |
Ameni BF 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 |
Ed Willink 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 |
Ed Merks 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 #1708454 is a reply to message #1707436] |
Wed, 16 September 2015 16:18 |
Ed Merks 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/
|
|
|
Goto Forum:
Current Time: Fri Apr 19 04:16:07 GMT 2024
Powered by FUDForum. Page generated in 0.02383 seconds
|