Book a Demo

Author Topic: Optimizing EA interface  (Read 4738 times)

Jim Beck

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Optimizing EA interface
« on: October 16, 2010, 10:30:19 am »
I sent this to tech support, but I thought I'd check with you all as well:

Hello.  We have rather naively written our add-in C# code so far.  We have noticed that when models scale up in size that functions in our add-in can take longer.  We have done a bit of profiling to see what is going on.  Often we iterate through the model collecting information on elements.  An example issue would be when looping through connectors for an element.  This takes a lot more time than anything else.  I will be gathering more information, but I wanted to ask you now if you have any advice on optimizing our add-in.  Is there a list of best practices?  I’m looking for things like “don’t loop through connectors like this: foreach (EA.connector c in e.connectors), do this instead” and such.  I’m even looking for general advice on speeding things up.  Debug versus Release build doesn’t seem to make any difference.  I am wondering about C++ versus C#, except that it is inside the EA COM interface that time appears to be spent most.  It seems funny that anything would take any length of time at all.  We are simply iterating through the model and it should be very fast indeed.  We only have a few hundred elements.  Any suggestions at all are greatly appreciated!

Thanks!

Jim Beck



mrf

  • EA User
  • **
  • Posts: 311
  • Karma: +0/-0
    • View Profile
Re: Optimizing EA interface
« Reply #1 on: October 18, 2010, 09:25:07 am »
I don't think programming language choice will affect performance here, it is more an issue of which tools to use for the job.

If you're iterating over large collections of things (such as packages, elements, connectors etc), then take a look at the Project interface - specifically the Enum methods (eg EnumPackages, EnumElements).

Instead of returning a Collection (and incurring the load time associated with initialising the collection), these methods return an XML document describing the things that you requested, and takes a lot less time to initialise. If you find an element/package/etc that is of interest, you can then load it with the function Repository.Get?????ByGUID() functions.

Project Interface API: http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/project_2.htm
Repository API: http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/repository3.htm
Best Regards,

Michael

[email protected]
"It is more complicated than you think." - RFC 1925, Section 2.8

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Optimizing EA interface
« Reply #2 on: October 18, 2010, 04:14:26 pm »
Jim,

I've had my share of performance problems writing addins on EA.
Here are the things I try to increase performance:
- Only iterate an EA collection once, an only if you really have to. You would think that iterating a collection in memory should be fast, but in fact in most cases EA will go to the database each time you do a next. Instead use put each object in a regular collection the first time you initialise it, and iterate over that.
- Use things like getElementSet passing an SQLString as parameter to get a specific set of elements, beats iterating over a larger collection of elements to filter out what you need.
- Use a caching mechanism for elements you have already initialised
- Use Repository.SQLQuery to get the id's of things you need, and initialise them using Repository.GetXXXByID
- If you don't need the EA objects then don't initialise them. E.g if you are doing an export of all classes to an excel file then use only Repository.SQLQuery to get the details you need, without initiliasing the classes themselves.
- Use Repository.BatchAppend and EnableCache and EnableUIUpdates
where appropriate.

Geert

Jim Beck

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Optimizing EA interface
« Reply #3 on: October 20, 2010, 10:02:28 am »
Thanks for those detailed answers!  I will be checking this out.

Jim