Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly
XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly [message #1695497] Fri, 15 May 2015 10:16 Go to next message
Sergio Otero is currently offline Sergio OteroFriend
Messages: 37
Registered: June 2012
Member
Hi

We're migrating a project with a very large grammar (2000 lines) that is used in projects with 8.000 files that occupy a total of 150Mb.

It seems to be taking longer than before. With JVisualVM i've seen that

org.eclipse.xtext.builder.clustering.ClusteringBuilderState.doUpdate()	100.0	105.562 ms (100%)	105.562 ms
	org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences()	37.76996	39.870 ms (37,8%)	39.870 ms
	org.eclipse.xtext.builder.clustering.ClusteringBuilderState.installSourceLevelURIs()	27.822605	29.370 ms (27,8%)	29.370 ms
		org.eclipse.xtext.ui.resource.DefaultResourceUIServiceProvider.isReadOnly()	27.81468	29.361 ms (27,8%)	29.361 ms
	org.eclipse.xtext.builder.builderState.AbstractBuilderState.updateMarkers()	14.870227	15.697 ms (14,9%)	15.697 ms
	org.eclipse.xtext.builder.resourceloader.AbstractResourceLoader$CheckedLoadOperation.next()	10.326545	10.900 ms (10,3%)	10.900 ms
	org.eclipse.xtext.builder.builderState.BuilderStateUtil.create()	5.5819836	5.892 ms (5,6%)	5.892 ms


The method installSourceLevelURIs is new to Xtext 2.8 and it is called every time clusteringPolicy.continueProcessing returns false (because our custom clusteringpolicy determines that there's not enought memory to continue without cleaning).

It seems to try to determine if every resource is readonly and it takes 30% of the linking phase.

Why is this needed?
Could i extend IResourceServiceProviderExtension to return "isReadOnly" to false always?
Maybe better extend ClusteringBuilderState to avoid calling to isReadOnly?

The first method resolveLazyCrossReferences consume 37% of time. Almost 1/3 of this time is due to class.getDeclaredMethod. This is because Java makes a copy of the declared methods to avoid anyone changing the info.
I've solved this problem in many applicacions with a guava cache with soft references.

org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.polymorphicFindScopeForReferenceName()	16.161259	17.060 ms (16,2%)	17.060 ms	86
	org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider$2.<init>()	12.731248	13.439 ms (12,7%)	13.439 ms	61
		org.eclipse.xtext.util.PolymorphicDispatcher.<init>()	12.731248	13.439 ms (12,7%)	13.439 ms	61
			org.eclipse.xtext.util.PolymorphicDispatcher.getDeclaredMethodsOrderedBySpecificParameterType()	12.713763	13.420 ms (12,7%)	13.420 ms	61
				java.lang.Class.getDeclaredMethods()	12.713763	13.420 ms (12,7%)	13.420 ms	61

@CallerSensitive
    public Method[] getDeclaredMethods() throws SecurityException {
        // be very careful not to change the stack depth of this
        // checkMemberAccess call for security reasons
        // see java.lang.SecurityManager.checkMemberAccess
        checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
        return copyMethods(privateGetDeclaredMethods(false));
    }


Thanks

Sergio
Re: XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly [message #1695504 is a reply to message #1695497] Fri, 15 May 2015 12:17 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Hi Sergio,

please file a ticket for these issues. We are in the end-game of 2.8.3
and it would be great to resolve any performance regressions along with
the other bugfixes. In the meantime you may want to mark your scope
provider as @Singleton and cache the dispatchers such that you avoid the
call to #getDeclaredMethod.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly [message #1695508 is a reply to message #1695504] Fri, 15 May 2015 12:52 Go to previous messageGo to next message
Sergio Otero is currently offline Sergio OteroFriend
Messages: 37
Registered: June 2012
Member
Ok, i will open 2 tickets

I have easyly overriden DefaultResourceUIServiceProvider to return isReadOnly always to false, but the other problem is not so easy to do.

For what i can see, PolymorphicDispatcher cannot be cached, so i have to extend it and overwrite getDeclaredMethodsOrderedBySpecificParameterType.
Then and i have to overwrite also AbstractDeclarativeScopeProvider.polymorphicFindScopeForReferenceName and polymorphicFindScopeForClassName, duplicating it's code, which is ugly ...

protected IScope polymorphicFindScopeForReferenceName(EObject context, EReference reference) {
		Predicate<Method> predicate = getPredicate(context, reference);
		PolymorphicDispatcher<IScope> dispatcher = new PolymorphicDispatcherParcheRend<IScope>(Collections
				.singletonList(this), predicate, errorHandler) {
			@Override
			protected IScope handleNoSuchMethod(Object... params) {
				if (PolymorphicDispatcher.NullErrorHandler.class.equals(errorHandler.getClass()))
					return null;
				return super.handleNoSuchMethod(params);
			}
		};
		EObject current = context;
		IScope scope = null;
		while (scope == null && current != null) {
			scope = dispatcher.invoke(current, reference);
			current = current.eContainer();
		}
		return scope;
	}
Re: XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly [message #1695523 is a reply to message #1695508] Fri, 15 May 2015 16:37 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Hey,

this is the part that should be cached:

Predicate<Method> predicate = getPredicate(context, reference);
PolymorphicDispatcher<IScope> dispatcher = new
PolymorphicDispatcherParcheRend<IScope>(Collections
.singletonList(this), predicate, errorHandler) {
@Override
protected IScope handleNoSuchMethod(Object... params) {
if
(PolymorphicDispatcher.NullErrorHandler.class.equals(errorHandler.getClass()))
return null;
return super.handleNoSuchMethod(params);
}
};

The cache key is the information that is used in #getPredicate, e.g. the
context's eClass and the reference name.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly [message #1695525 is a reply to message #1695523] Fri, 15 May 2015 17:34 Go to previous messageGo to next message
Sergio Otero is currently offline Sergio OteroFriend
Messages: 37
Registered: June 2012
Member
The code is using the EObject instance to get the Predicate, so i though i couldn't cache at that level for the eClass

I'll try monday

Thanks a lot.

Sergio
Re: XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly [message #1695580 is a reply to message #1695525] Sun, 17 May 2015 10:12 Go to previous messageGo to next message
Sergio Otero is currently offline Sergio OteroFriend
Messages: 37
Registered: June 2012
Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=467456
https://bugs.eclipse.org/bugs/show_bug.cgi?id=467457
Re: XText 2.4.3 to 2.8.2 performance problems in getDeclaredMethods and isReadOnly [message #1695630 is a reply to message #1695580] Mon, 18 May 2015 09:01 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
On 17.05.15 12:12, Sergio Otero wrote:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=467456
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=467457

Thanks a lot, we'll look into both issues for 2.8.3

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Previous Topic:keywords in grammar
Next Topic:"Basic"(Language) sample Project
Goto Forum:
  


Current Time: Wed Apr 14 09:31:29 GMT 2021

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

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

Back to the top