Setting UserParameter.expression sporadically slows down

Setting UserParameter.expression sporadically slows down

marcosscriven
Enthusiast Enthusiast
514 Views
3 Replies
Message 1 of 4

Setting UserParameter.expression sporadically slows down

marcosscriven
Enthusiast
Enthusiast

I have been having issues with a script sporadically running very slowly.

 

I've narrowed it down to a test where this is the entirety of the run() method:

 

 

app = adsk.core.Application.get()
design = adsk.fusion.Design.cast(app.activeProduct)

for param in design.allParameters[:10]:
   # print(param.name, param.objectType, param.expression)
   param.expression = param.expression + ' '

print('Done')

 

 

 

Even with just 10 items, sometimes the UI goes black, and it takes 30 seconds to run this.

 

I'm setting the param expression so that it doesn't actually change value here, to see if it was something to do with the model resizing.

 

What's even harder to understand is that this is fast sometimes, especially when run the first few times. Then, all of a sudden, it just runs at less than a 10th of the speed.

 

I even tried removing the print statement in the loop, in case that was somehow blocking the thread.

 

EDIT - I'm not even sure it's anything to do with params. Just suddenly even getting to the first line of the script slows down.

0 Likes
515 Views
3 Replies
Replies (3)
Message 2 of 4

marcosscriven
Enthusiast
Enthusiast

I think one thing confusing matters is using debug attachment for logging. So I've just tried logging to a file with timestamps, and now I can indeed see it is indeed setting model param expressions takes 1.5 seconds, even if the expression isn't really changed.

This seems to change radically for a model that's much simpler. I'm guessing something is being re-evaluated, even though it doesn't end up changing.

I wonder if there's a way to turn that off until I'm done changing params?

0 Likes
Message 3 of 4

Anonymous
Not applicable

Do you have those expressions used in a bunch of sketches? I've definitely seen that kind of performance hit if you update expressions in multiple sketches.

 

I typically disable computation on sketches when updating expressions; using the sketch's isComputeDeferred function, and then re-enable computation when my expressions are updated.

 

Unfortunately, if those expressions are used in a lot of features, patterns, etc, I haven't found a way to disable computation while updating.

Message 4 of 4

marcosscriven
Enthusiast
Enthusiast

I've just been experimenting with this directly in the UI, and it seems the issue happens there too. The difference seems to be how early on in the history the dimension was created.

If I change the dimension to 'dimension + 0' (so no actual change) on a parameter for a box I created right at the beginning, it takes the UI 2 seconds to be responsive again.

If I change a dimension only used in a recent extrude, it's virtually instant.

What I really need therefore is either something to suspend re-evaluating if there's no actual change, or something to suspend re-evaluating every single time.

0 Likes