Retrieving the instance count of a given Mendix Object

Is there a better way to retrieve the number of objects of a given type in a mendix application, currently i'm using the following Java code: Core.retrieveXPathQuery(getContext(), "//" + MendixObject.getType).size() However this approach slows an application down considerably as the number of instances of an object grows. I can appreciate this takes a long time as the method returns a list of type IMendixObject and therefore instantiates each object of the given type. Is there a better way to get this value without all the instantiation?
1 answers

Core.retrieveXPathQueryAggregate(IContext context, String xpathQuery) returns a Long with the count.