Editing block properties performance issue

When working with dynamic blocks, I can imagine that the functionality most used are
- Block Properties
- Block Attributes
- Maybe some Extension Dictionary editing.

At least, that is what we worked with most in our last project. It was pretty much based on positioning and editing Dynamic Blocks.
At the time, we had noticed some performance issues when we were inserting or editing a lot of blocks. This actually became annoying when we were doing operations that changed 40 or more blocks.

At first, we thought that the problem was in our calculation and processing. We had a pretty intense Processing engine for the blocks and our reaction was that we were processing things too much.

When we started investigating what caused the performance lag, we actually found that our processing was quite fast, but that the problem was editing a lot of Blocks. So, the problem was not our code; the timely operation was, waiting for AutoCAD operations to complete.

So we isolated the functionality of accessing and editing blocks to see what exactly went wrong.

We tried:
- using less transactions (all can be done in one single transaction), no luck.
- rewriting our code, so there would be less loops, no luck.

As we investigated a little further, with timers on each operation we did, we finally found out that it were actually the block properties that were the slowness factor...

The results were quite remarkable, as a reference:

Inserting 100 blocks with 4 attributes and 4 properties takes us: 1000ms, so 1 second.

In this second we have:

Code overhead: 62ms
Inserting block: 32ms
Set attributes: 47ms
Set properties: 859ms

This means that setting the properties takes more than 85% of complete operation time.

Now, you can say that, since this all still happens in one second, that there isn't a big performance issue. However, our blocks easily had 8-10 properties. So spending 85% of your time in updating properties is in fact a lot.

Next time, we'll look in how to get around this issue.

Posted by Bert Vanpeteghem

3 reacties:

Mark said...

Iterating and updating of attdefs is something which is quite often used.
You wanted to post a continuation, how about that ?

Bert Vanpeteghem said...

Hi Mark,
I was waiting for a reaction like this to actually write a follow up on this post.

And to be honest, I have not yet found a practical way to handle this issue.

The best way to get around this is avoiding to update the dynamic properties. Which can be done by tracking changes on the blocks and the properties you need to edit.

So, if you're having problems the performance as well, I'd recommend writing some code that tracks the made changes before updating the blocks.

Any other ideas would sure be welcome as well :).

Btw, you mention attdefs. My problems were mainly with the dynamic properties, and as I can remember, not with the attributes. Are you having problems with the attributes as well?

Mark said...

Hi Bert,

I'm still in the development phase and have no mass data so far. I also do not have to deal with dynamic properties.
But ACAD contains so many pitfalls, that it may save you a lot of time, when you know them. So I try to remember where someone stumbled over a problem :)