Page 1 of 1

Optimizing Creating Instances and Initing Slots

PostPosted: Thu Feb 13, 2020 11:47 am
I am wondering if anyone has any feedback on how I could more efficiently add slot data to newly created instances. Right now I am using jython, and will probably look at migrating to a java plugin, but I expect I will see a similar bottleneck.

So first, here is the example code.

Code: Select all
      class_inst = AutomatonMacroAPI.createElement("InstanceSpecification")


      ModelHelper.createSlotsForDefaultValues(class_inst._getRepresentElement(), True)

      get_slot = class_inst.getSlot()
      total_slots = len(get_slot)

      for slot_index in range(total_slots):
         slot_item = get_slot.get(slot_index)

         if slot_item.getDefining_Feature().getName() in data_item:
            value_spec = ModelHelper.createValueSpecification(

So, in this example, most things don't take too long.
createSlotsForDefaultValues is %16 of the time
createValueSpecification and adding the spec is 12% of the time
get_slot.get(slot_index) is 72% of the time

It seems like there is probably a better way I could do this, instead of iterating through the defaulted slots, if I could do it however createSlotsForDefaultValues does it, that would save me a lot of time.

Scaled up, this macro is taking 20 minutes as I call getSlot().get() 25000 times. I can maybe look at manually creating the slot, and then adding it, but was struggling with setting the defining feature, and that made cameo mad at me.

Re: Optimizing Creating Instances and Initing Slots

PostPosted: Thu May 14, 2020 9:25 pm
So, I finally had a chance to port to Java as a plugin.

Simply porting the code as is, dropped it down to about 44 seconds.

In addition, the following code segment in Java dropping it to about 11 seconds. This is something I could not get to work using the Automation Macro API because setDefiningFeature was giving me trouble. So, plugins are for sure faster.

Code: Select all
Slot slot = factory.createSlotInstance();
ValueSpecification value_spec = ModelHelper.createValueSpecification(