Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Caches in Code Generator
Caches in Code Generator [message #1790443] Mon, 11 June 2018 08:30 Go to next message
Oliver Libutzki is currently offline Oliver LibutzkiFriend
Messages: 38
Registered: September 2011
Member
Hi,

I would like to cache certain information which is used in my code generator. The information is derived from my domain model (Ecore model). As calculation is expensive, I would like to cache the results.

The calculation takes several resources into account, so using a org.eclipse.xtext.util.OnChangeEvictingCache seems not to be feasible as the cache is only invalidated, if a resource is changed semantically.

In other words I would like to invalidate the cache for a certain resource every time org.eclipse.xtext.resource.IResourceDescription.Manager.isAffected(Delta, IResourceDescription) returns true.

Is this possible and does a corresponding implementation already exist?

An alternative approach is to invalidate the whole cache before every generator run (build). org.eclipse.xtext.builder.BuilderParticipant.build(IBuildContext, IProgressMonitor) seems a good method to hook in for the UI (Eclipse) scenario.

What do you think about these ideas or do you have any ready-made solution?

Kind regards
Oliver
Re: Caches in Code Generator [message #1790445 is a reply to message #1790443] Mon, 11 June 2018 08:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12356
Registered: July 2009
Senior Member
i dont know of a general exisiting cache for that but to do is at the start of the builderparticipant sounds feasable.
what i dont get is why using a onchangeeviting cache is not usable: it will invalidate too often and not too seldom.

=> would be interesing to understand more about the nature of the thing you want to cache.
e.g. you could use a listener on indexing events to do the invalidation
(org.eclipse.xtext.resource.IResourceDescription.Event.Listener)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Caches in Code Generator [message #1790446 is a reply to message #1790445] Mon, 11 June 2018 08:58 Go to previous messageGo to next message
Oliver Libutzki is currently offline Oliver LibutzkiFriend
Messages: 38
Registered: September 2011
Member
I try to describe it in a simplified abstracted example:

I have two entities EntityA and EntityB. EntityA can reference multiple instances of EntityB (one-to-many).

EntityB has attributes. These attributes need to be taken in account whenever code for EntityA is generated.

I have an extension method like getAllAttributes(EntityA entityA) which collects all the attributes of the referenced entities (EntityB).

getAllAttributes(EntityA entityA) is called many times for the same instance of EntityA. Therefore the result should be cached. But invalidating the cache whenever EntityA is changed is not sufficient as the result is affected by changes in the referenced entities (EntityB).


Re: Caches in Code Generator [message #1790455 is a reply to message #1790446] Mon, 11 June 2018 10:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12356
Registered: July 2009
Senior Member
maybe you can have a cache based on index events.
the other question is what really makes the generation slow so that you need to cache at all.


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Caches in Code Generator [message #1790669 is a reply to message #1790455] Thu, 14 June 2018 08:05 Go to previous message
Oliver Libutzki is currently offline Oliver LibutzkiFriend
Messages: 38
Registered: September 2011
Member
In the end it turned out that the transformation is so fast that no caching is needed. ;-)

But in general hooking into the BuilderParticipant seems to be the right place.
Previous Topic:Problem parsing expression
Next Topic:Mixin Xtext with other models
Goto Forum:
  


Current Time: Mon Nov 12 17:33:58 GMT 2018

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

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

Back to the top