Author Topic: Updating attributes through the API is very slow  (Read 2854 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11251
  • Karma: +415/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Updating attributes through the API is very slow
« on: June 22, 2021, 04:16:50 pm »
I had imported an xsd that contained an enumeration with lots of values 4000.
The name of the value was a numeric code, and the description of that code was imported into the notes.
I wanted to put the descrption into the alias so I could see the meaning of the values on a diagram by showing the alias, so I wrote a little script to do so (see below)

I ran this script on a few other imported XSD's and it was finished whithin a minute or so, but when it came to the xsd with the enumeration mentioned, it took ages.
I let it run, and it finally finished after 13 hours!

That is an average of over 11 seconds for each attribute. This is not workable anymore. Something should be done to improve the performance of the API in these circumstances.


Code: [Select]
const outputName = "CopyNotesToAlias"

sub main
'create output tab
Repository.CreateOutputTab outPutName
Repository.ClearOutput outPutName
Repository.EnsureOutputVisible outPutName
'get selected package
dim package as EA.Package
set package = Repository.GetTreeSelectedPackage
'inform user
Repository.WriteOutput outPutName, now() & " Starting CopyNotesToAlias for package '" & package.Name & "'", 0
'do the actual work
copyNotesToAlias package
'inform user
Repository.WriteOutput outPutName, now() & " Finished CopyNotesToAlias for package '" & package.Name & "'", 0

end sub


function copyNotesToAlias(parent)
dim element as EA.Element
for each element in parent.Elements
'inform user
Repository.WriteOutput outPutName, now() & " Processing element '" & element.Name & "'", 0
'move notes to alias
if len(element.Notes) > 0 then
element.Alias = Repository.GetFormatFromField("TXT", element.Notes)
element.Update
end if
'process attributes
dim attribute as EA.Attribute
for each attribute in element.Attributes
'move notes to alias
if len(attribute.Notes) > 0 then
attribute.Alias = Repository.GetFormatFromField("TXT", attribute.Notes)
attribute.Update
end if
next
'process subElements
copyNotesToAlias element
next

end function

main

Reported

Geert

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1111
  • Karma: +102/-9
  • Its the results that count
    • View Profile
Re: Updating attributes through the API is very slow
« Reply #1 on: June 23, 2021, 11:30:50 am »
Yeah that performance really sucks. Whilst waiting for Sparx to reply and possibly grant your wish, I see you've written it in VBScript. Would be interesting to see if its any faster in JScript or JavaScript but I guess you wouldn't want to repeat it if it takes close to 13 hours. The reason I mention it is that I did see an article about JScript and VBScript performance a while back and IIRC JavaScript was 20 times faster. Not sure if that translates in to the Sparx EA environment but would be interesting to see for future reference. You could add a timestamp at the start and then the end of the process so you don't have to sit there timing it.

Happy to help
:)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11251
  • Karma: +415/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating attributes through the API is very slow
« Reply #2 on: June 23, 2021, 02:40:58 pm »
I'm pretty sure the bottleneck is the API, and not the language used to call it.
I see the same type of thing when using C#

Geert