PowerPoint takes more time each time I execute my addin code

Add-in Express™ Support Service
That's what is more important than anything else

PowerPoint takes more time each time I execute my addin code
 
momsoft




Posts: 79
Joined: 2004-06-16
My addin does a lenghty operation (Update TOCs). It creates, reformats and updates many slides. The problem is that the operation takes more time everytime I execute the operation.

This is a typical sequence of executions:

Time ellapsed 1.188 s
Time ellapsed 2.406 s
Time ellapsed 3.765 s
Time ellapsed 5.078 s
Time ellapsed 6.468 s
Time ellapsed 7.734 s

The sequence repeats almost with the same values if PowerPoint is restarted, and usually closing and reopening the presentation, without closing PowerPoint also resets the timings.

Other than this, the add-in works perfectly, it does not report any exception or memory leak.

Maybe the problem is that since I want to use the new Office 2007 object model I am linking to PowerPoint using the following code:

var
ppt : PowerPoint_TLB.PowerPointApplication;

...

procedure TAddInModule.ConnectToPowerPoint;
var
IUnk : IUnknown;
begin
GetActiveObject(CLASS_PowerPointApplication, nil, IUnk);
IUnk.QueryInterface(_Application, ppt);
end;

I invoke ConnectToPowerPoint on the adxCOMAddInModuleAddInInitialize event and always use the ppt variable to access PowerPoint related objects.
Posted 19 Jul, 2017 09:24:33 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Manuel,

You should import the required type library, retrieve the self.PowerPointApp property and cast it; find an example at https://www.add-in-express.com/forum/read.php?FID=1&TID=12731&MID=64876#message64876.

But I doubt the issue relates to using or not using a type library.

If the sequence you posted means that every run takes more and more time, I suppose there's some problem in the add-in logic.

Also check if https://stackoverflow.com/questions/28511508/turn-off-screenupdating-for-powerpoint provides a useful suggestion.


Andrei Smolin
Add-in Express Team Leader
Posted 20 Jul, 2017 05:19:11 Top
momsoft




Posts: 79
Joined: 2004-06-16
Andrei,

Thank you for your suggestions. I am already using a similar procedure for preventing PowerPoint from updating but it does not seem to make any difference. The execution times are the same when I comment the calls to LockWindowUpdate, and at least on PowerPoint 2016, the window does not update until the end of the process.

With respect to the other issue, I agree that it will not solve the problem but I am hoping I might get better performance for my add-in.

I saw the forum post you mention, but the example is for Outlook and it doesn't work with PowerPoint:

If I use:

ppt := self.PowerPointApp.Application as PowerPoint_TLB._Application

I get a compile time error because MsPpt200.TPowerPointApplication does not contain a member called Application

If I use:

ppt := self.PowerPointApp as PowerPoint_TLB._Application

I get a runtime exception EIntfCastError in module PowerTOC.dll at 00000000. Interface not supported.

Kind regards,

Manuel
Posted 20 Jul, 2017 06:22:43 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Manuek,

Try ppt := self.PowerPointApp.DefaultInterface as PowerPoint_TLB._Application.


Andrei Smolin
Add-in Express Team Leader
Posted 20 Jul, 2017 08:44:58 Top
momsoft




Posts: 79
Joined: 2004-06-16
Andrei,

Thank you. That worked!

I don't see a drastic performance improvement, but I will use your method.

With respect to the issue of degrading performance. It seems that PowerPoint becomes "tired" somehow if you execute the code many times in a row, but simply closing the presentation and opening it again solves the problem. I will continue experimenting to see if I am able to discover what could be happening.

Thank you very much,

Manuel
Posted 20 Jul, 2017 10:23:14 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Manuel,

Consider releasing all COM objects: set nil to all variables containing references to the PP object model.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jul, 2017 05:12:23 Top
momsoft




Posts: 79
Joined: 2004-06-16
Andrei,

I also believe that not releasing COM objects is the problem.

I have created a test application that uses the same code, but is not loaded as an add-in. The performance is one order of magnitude slower than the add-in, but it confirms that the problem is not on my code because if I close the program and reconnect to PowerPoint, the same degrading performance issue is maintained.

The problem is that I have been very careful setting all variables to nil after using them and I am trapping all exceptions, so I am sure they are actually being set to nil. Also, I am now passing all these variables as const whenever I use them in a method.

I will continue hunting my code ...

Kind regards,

Manuel
Posted 21 Jul, 2017 06:31:10 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Manuel,

Could you try to cut off some parts of your code to find the minimal set of code required to reproduce the issue?

What PowerPoint build are you using? Is is 32bit or 64bit?


Andrei Smolin
Add-in Express Team Leader
Posted 24 Jul, 2017 05:00:11 Top
momsoft




Posts: 79
Joined: 2004-06-16
Dear Amdrei,

I am using 32 bit PowerPoint.

I have done that. Can I send you the test project?

Kind regards,

Manuel
Posted 24 Jul, 2017 11:55:55 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Manuel,

Please send me the project to the the support email address. You can find it in {Add-in Express installation folder}\readme.txt. Please make sure your email contains a link to this topic.

What PowerPoint build are you using? Is is 32bit or 64bit?


Andrei Smolin
Add-in Express Team Leader
Posted 25 Jul, 2017 03:58:06 Top