Bug 442558 - [CDO] CDOResourceImpl.getURI() is inefficient
Summary: [CDO] CDOResourceImpl.getURI() is inefficient
Status: NEW
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 4.13   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-26 06:09 EDT by Leonid Ripeynih CLA
Modified: 2020-12-11 10:42 EST (History)
2 users (show)

See Also:


Attachments
Profiling result (115.44 KB, image/png)
2014-08-26 06:09 EDT, Leonid Ripeynih CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leonid Ripeynih CLA 2014-08-26 06:09:10 EDT
Method CDOResourceImpl.getURI() can take tens of milliseconds to execute, for resources with about ten parent folders.

Given that this method can be extensively on operations such as AbstractCDOView.newResourceInstance() it perfomance is quite important.

I'm attaching a profiler screenshot to illustrate the problem.

Discussion is here: 
https://www.eclipse.org/forums/index.php/t/802305/
Comment 1 Leonid Ripeynih CLA 2014-08-26 06:09:36 EDT
Created attachment 246350 [details]
Profiling result
Comment 2 Leonid Ripeynih CLA 2014-09-04 08:20:08 EDT
After some research, I came with the following analysis:
It's not getURI() itself causing low performance, it's newResourceInstance(), that iterates over all loaded resources (three times). So, for loading large amount of resources, algorithm becomes effectively quadratic. I've done an experimental optimization using EMF ResourceLocator mechanism, and it works wonders. 

Here is how it works: it maintains a cache of URI -> Resource (normal hash map). It also attaches itself as CDOObject handler to each view, that are in its resourceSets viewSet. When a CDOResourceNode goes to a NEW or CLEAN state, it attaches an adapter to it. Adapter listens to notifications in its 'folder' and 'name' features, and whenever one changes it sets a flag 'updateCacheOnNextGetResource'.

In getResource method it checks the flag, and if it's set, it recalculates the URI's for all already cached resources. After this it's O(1) to check if a resource exists, and return or create a new one.

Unfortunately, that's not enough. CDO iterates over all resources in org.eclipse.emf.internal.cdo.view.AbstractCDOView.ensureURIs(ResourceSet), bypassing ResouceSetImpl.getResource(). It's said that it fixes bug 337523. But, after I commented it out, test for this bug still passes, so it's probably safe to remove.
Comment 3 Eike Stepper CLA 2014-09-04 12:27:41 EDT
Hi Leonid, Thanks for the analysis. If you contribute a Gerrit review I'Ll probably find some time to review it and research why ensureURIs() no longer seems needed.
Comment 4 Eike Stepper CLA 2015-07-14 02:15:09 EDT
Moving all open bugzillas to 4.5.
Comment 5 Eike Stepper CLA 2016-07-31 00:58:09 EDT
Moving all unaddressed bugzillas to 4.6.
Comment 6 Eike Stepper CLA 2017-12-28 01:20:14 EST
Moving all open bugs to 4.7
Comment 7 Eike Stepper CLA 2019-11-08 02:05:41 EST
Moving all unresolved issues to version 4.8-
Comment 8 Eike Stepper CLA 2019-12-13 12:49:28 EST
Moving all unresolved issues to version 4.9
Comment 9 Eike Stepper CLA 2020-12-11 10:42:50 EST
Moving to 4.13.