Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » code optimization
code optimization [message #1758741] Sat, 01 April 2017 14:40 Go to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Hi,

The execution of the below code, takes a lot of time, Does anyone have a idea to optimize it?
if (MM_ETL!TransformationRule -> allInstances() -> exists (l|
l.source.resolvedType.elementName=MM_Src!EStructuralFeature.allInstances() -> select (s|s.name=a.target.collectAllContainedElements()->last().name)-> collect (s|s.eType.name)->first()
or
MM_Src!EClass.allInstances() -> select(s|s.eSuperTypes.includes((MM_Src!EStructuralFeature.allInstances() -> select (s|s.name=a.target.collectAllContainedElements()->last().name)-> collect (s|s.eType)->first())))-> select (s|s.name=l.source.resolvedType.elementName))->notEmpty()
))



I also write it in the below form, but it also takes about 5 minutes.
if (MM_ETL!TransformationRule -> allInstances() -> exists (l|
(MM_Src!EClass.allInstances() -> select(s|s.eSuperTypes.includes((MM_Src!EStructuralFeature.allInstances() -> select (s|s.name=a.target.collectAllContainedElements()->last().name)->first().eType)))-> collect (s|s.name))
.append(MM_Src!EStructuralFeature.allInstances() -> select (s|s.name=a.target.collectAllContainedElements()->last().name)->first().eType.name).includes(l.source.resolvedType.elementName)
))

any comment is appreciated.

[Updated on: Sat, 01 April 2017 18:41]

Report message to a moderator

Re: code optimization [message #1758797 is a reply to message #1758741] Mon, 03 April 2017 09:36 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
I think this is because I compute "MM_Src!EStructuralFeature.allInstances() -> select (s|s.name=a.target.collectAllContainedElements()->last().name" twice.
How can I compute it once for expression "a"?

if I call the operation helper such as below, it still runs twice.
helper def: getType(a : MM_ETL!Expression) : String =
MM_Src!EStructuralFeature.allInstances() -> select (s|s.name=a.target.collectAllContainedElements()->last().name)->first().eType.name	
;

[Updated on: Mon, 03 April 2017 09:40]

Report message to a moderator

Re: code optimization [message #1758804 is a reply to message #1758797] Mon, 03 April 2017 11:03 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 552
Registered: July 2009
Senior Member
Have a look here
Re: code optimization [message #1758819 is a reply to message #1758804] Mon, 03 April 2017 13:49 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
As I want to pass a variable "a" to it, I can not use Attribute helper.
but your link really helped me I used let expression to define a variable. thanks.
Re: code optimization [message #1758838 is a reply to message #1758819] Mon, 03 April 2017 15:33 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 552
Registered: July 2009
Senior Member
Re-read this chapter because I don't think you understood the "context" part.
Re: code optimization [message #1758843 is a reply to message #1758838] Mon, 03 April 2017 17:00 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Oh, Yes. if I write something like a.helper-name, I can use "a" in the helper with self keyword.
Re: code optimization [message #1758885 is a reply to message #1758843] Tue, 04 April 2017 07:22 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 552
Registered: July 2009
Senior Member
That's it and it will be computed only one time no matter how many times it's called.
Re: code optimization [message #1758888 is a reply to message #1758885] Tue, 04 April 2017 07:54 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Thanks so much.
if I have 3 expression "a", "b" and "c" and I want that code execute one time for "a", one time for "b" and one time for "c", can not I use it?
Re: code optimization [message #1758894 is a reply to message #1758888] Tue, 04 April 2017 09:05 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 552
Registered: July 2009
Senior Member
Yes you can, it's one time per context element.
Re: code optimization [message #1758904 is a reply to message #1758894] Tue, 04 April 2017 12:09 Go to previous message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 262
Registered: July 2016
Senior Member
Thanks for your kind help.
Previous Topic:InPattern and outPattern Elements
Next Topic:different condition levels in filter of the rule
Goto Forum:
  


Current Time: Tue Jan 16 19:31:17 GMT 2018

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

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