Optimizations and fine tuning
Now that we implemented this DSL with a test suite, we can concentrate on refactoring some parts of it in order to optimize the performance.
In the Forward references section, we implemented the method variablesDefinedBefore
and we anticipated that its performance might not be optimal. Since that method is used in the validator, in the type system and in the content assist it would be good to somehow cache its results to improve the performance.
Caching usually introduces a few problems since we must avoid that its contents become stale. Xtext provides a cache that relieves us from worrying about this problem, org.eclipse.xtext.util.IResourceScopeCache
. This cache is automatically cleared when a resource changes, thus its contents are never stale. Moreover, its default implementation is annotated as com.google.inject.Singleton
, thus all our DSL components will share the same instance of the cache.
To use this cache we call the method:
<T> T get(Object key...