Author Topic: guidelines for creating elements  (Read 6932 times)

Adam@Schneider

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
guidelines for creating elements
« on: October 27, 2014, 05:42:20 pm »
Hi,

I'm making a lot of calls to Element.Elements.AddNew and Package.Elements.AddNew.

This is very slow, I'm wondering if there are any guidelines or best practices? Obviously I have to AddNew and then call Update on the new item, but do I need to Update and Refresh the collection before adding more in C#)?

I've found the Bulk update parameter on the repository, is there anything else I should/should not be doing?


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: guidelines for creating elements
« Reply #1 on: October 27, 2014, 07:20:41 pm »
The update actually creates the element. So you need that. The refresh just updates / re-reads the collection if you want to iterate over it. This is only needed in very few cases since you know that you added the element. This means that you can leave out the refresh.

It *is* possible to bypass the API and create elements directly in EA's database but I would not really recommend it for a couple of obvious reasons. But sometimes other forces are stronger...

q.

P.S. I once measure the effect of the bulk update parameter and it was near to nil. Maybe it has been improved but I doubt that.
« Last Edit: October 27, 2014, 07:23:55 pm by qwerty »

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: guidelines for creating elements
« Reply #2 on: October 29, 2014, 03:51:14 am »
I believe there is also Repository.EnableUIUpdates and Repository.EnableCache that if set to false and true respectively might help...

Adam@Schneider

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: guidelines for creating elements
« Reply #3 on: October 29, 2014, 12:22:37 pm »
Thanks.

It seems the biggest performance improvement comes from not using a remote database and doing the work on a local model.

I was creating about 150 elements and a heap more connectors and over the network to our cloud server this was taking close to 2 hours, using a local EA file it does it in under 5 minutes. Based on my performance monitoring it looks like there are a lot of sequential round trips to the database. I think the workflow for this operations is going to be to do a model transfer to a local file, run the import, do an XMI export and an XMI import.

Alternatively I could be smarter in my addin, how threadsafe is EA? Can I spawn multiple threads and do some unrelated operations in parallel? Related to this, it seems the addin does all its work in the GUI thread, giving EA the appearance of locking up, I have been good and created an output tab for my addin and sent progress there, but in long operations it isnt updated. Can I do the work in another thread and somehow leave EA responsive enough to redraw itself? I dont mind throwing up a progress dialog so the user cant touch anything.

If I can harness the power of threads I should be able to batch up my operations on the client side and use a thread pool or something to churn through them.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: guidelines for creating elements
« Reply #4 on: October 30, 2014, 08:53:35 am »
EA is not threadsafe. At all.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: guidelines for creating elements
« Reply #5 on: October 30, 2014, 10:33:32 am »
You could start multiple instances, but then you'd need some locking. That wouldn't make sense either.

q.

Adam@Schneider

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: guidelines for creating elements
« Reply #6 on: October 30, 2014, 11:49:21 am »
And conversely, if I want to properly delete an element, is removing it from the owning packages Elements collection enough? or if it is a nested element from the owning elements collection? Will all connectors go the same as if you delete if from the tree or diagram manually?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: guidelines for creating elements
« Reply #7 on: October 30, 2014, 09:29:25 pm »
Luckily EA will do that job for you. So if you delete an element it will automatically delete all connectors too. And of course all containing elements. Though all instances are kept since they are now individuals  ;) Any types where the class has been used now just keep the name.

q.