http://qs321.pair.com?node_id=485946

guha has asked for the wisdom of the Perl Monks concerning the following question:

Background:
A few weeks ago my home office was hit by lightning and most of my equipment was zapped, phone, modem, router and computer. After a few tears I replaced the stuff and to my joy the HD from the old box was accessible and I could copy data and scripts easily.

I reinstalled the application software like perl, Office, editor, etc on the new harddrive which has MS XP Pro SP2 preinstalled, same as on the old box which had been upgraded to SP2 a couple of months ago. During this quest I have reinstalled perl and Office just to make sure.

I have a rather large application written in Perl which uses Win32::OLE to control MS Word. The app generates reports with tables in them, it IS pretty slow due to OLE and Word, neither one a speed demon. The application draws a lot a CPU, nearly 100 % for several minutes, when Word does it's chores.

Problem:
However on the new computer, which is a few times more powerful compared to the old one, the parts of the application which deals with Word is running very slowly, in the order 10 times slower. The CPU-load is between 0 and 5 %.

Stuff like saving to disk and printing from Word seems OK. I think that it is the marschalling between perl and Word which has gone awry. Some new security feature or what ?

I have been searching google, microsoft, activestate but no avail. This is kinda my last straw ... any ideas ?

Replies are listed 'Best First'.
Re: MS Word over Win32::OLE "suddenly" extremely slow
by puploki (Hermit) on Aug 23, 2005 at 20:40 UTC

    A couple of thoughts, although none of them are fabulous:

    • Use Process Explorer to try and look at what process are using what memory/CPU/file handles.
    • Everyone says it, and I'm sure you've thought of it, but check any antivirus settings. Word also has a really annoying inbuilt virus checker thingy for macros. I don't know if that's interfering?
    • If your OS is running XP SP2 or Server 2003 SP1, try disabling Data Execution Protection (DEP) on the vague off chance. See KB875352 for details.
    • Maybe try upgrading to Office 2003 SP1?

    Sorry these aren't great suggestions :(

      I think they are great suggestions!

      Use Process Explorer to try and look at what process are using what memory/CPU/file handles.

      Downloaded and tested PE, which is a nice addition to the toolbox, the only new thing that I could see was that there was a rather large amount of context switching going on in WINWORD.EXE, in fact in excess of 1000 switches/sec. I don't know if that is a problem, will try to check that out on another computer.

      Everyone says it, and I'm sure you've thought of it, but check any antivirus settings. Word also has a really annoying inbuilt virus checker thingy for macros. I don't know if that's interfering?

      Yes this was my first thought, so that has been tested. And I've checked Word's configuration and there is no virus/macro check enabled.

      If your OS is running XP SP2 or Server 2003 SP1, try disabling Data Execution Protection (DEP) on the vague off chance. See KB875352 for details.

      This idea had I already explored before posting here. But the link was welcome information.

      Thanks again!

        Along with the anti-virus, don't forget your anti-spyware to be on the safe side: spybot, spywareblaster (both available on http://www.downloads.com) and Microsoft Anti-Spyware from http://www.microsoft.com

        Jason L. Froebe

        Team Sybase member

        No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: MS Word over Win32::OLE "suddenly" extremely slow
by spiritway (Vicar) on Aug 24, 2005 at 04:52 UTC

    Is it possible that your data files were somehow corrupted? I encountered a similar problem - Word got extremely slow, and it turned out that the file I was trying to work on had been corrupted. It wasn't quite enough to blow up Word, but it did slow it down to a crawl.

      Tested but no change for the better. Thanks anyway!

Re: MS Word over Win32::OLE "suddenly" extremely slow
by wfsp (Abbot) on Aug 23, 2005 at 17:41 UTC
    I have an app that sucks in text from a Word file and have never had any problems.

    Are you able to post a short piece of code that demonstrates the problem so we could have a look?

    winXP SP2 (home), Office 2003, Activestate 5.8.7.

      Here is a short example that displays the problem on the new computer

      #!perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const; use Cwd; print "Load Const\n"; my $wdc = Win32::OLE::Const->Load("Microsoft Word") || die "Unable to load constants ", Win32::OLE->LastError(); print "Load Word Engine\n"; my $Word = Win32::OLE->new('Word.Application', 'Quit') || die "Unable to start Word Engine ", Win32::OLE->LastError(); $Word->{'Visible'} = 0 ; $Word->{'DisplayAlerts'} = 0; ## Open template print "Add new doc\n"; my $doc = $Word->Documents->Add() || die"Unable to open new doc ", Win32::OLE->LastError(); # Turnoff background operations $Word->Options->{'Pagination'} = 0; $Word->Options->{'PrintBackground'} = 1; $Word->Options->{'BackgroundSave'} = 0; my $range = $doc->Content; $range->Collapse( {Direction => $wdc->{wdCollapseEnd} } ); my $max_row = 25; my $max_col = 7; print "Creating table $max_row x $max_col\n"; my $t1 = $doc->Tables->Add($range, $max_row, $max_col); my $start = time; print "Start Data Entry\n"; foreach my $row (1 .. $max_row) { foreach my $col (1 .. $max_col) { $t1->Cell($row, $col)->Range->{Text} = "$row-$col"; } } print "Finished Data Entry ", time - $start, " secs\n"; $start = time; print "Start Center\n"; foreach my $row (2 .. $max_row) { foreach my $col (1,3,5.. $max_col) { $t1->Cell( $row, $col )->Range->ParagraphFormat->{'Alignment'} + = $wdc->{'wdAlignParagraphCenter'}; } } print "Finished Center ", time - $start , " secs\n"; my $path = cwd; my $out_file = "$path/word_ole.doc"; $out_file =~ s{\/}{\\}g; $doc->SaveAs($out_file); $doc->Close( { SaveChanges => $wdc->{wdDoNotSaveChanges} } );

      I have timed this on three different computers. On the new one it takes around 50 secs to enter data and 70 secs to center data. Whereas on the others enter and center takes around one second each, which is what I was used to.

        ---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" guha.pl Load Const Load Word Engine Add new doc Creating table 25 x 7 Start Data Entry Finished Data Entry 1 secs Start Center Finished Center 1 secs > Terminated with exit code 0.
        It looks like I'm with the 'others' :-)

        Hope the other replies help you identify what's happening.

        John

Re: MS Word over Win32::OLE "suddenly" extremely slow
by anonymized user 468275 (Curate) on Aug 24, 2005 at 12:51 UTC
    Perhaps there are some configuration differences. Apart from the system swap file configuration, you could also check for differences in the new win.ini file from the previous installation.

    One world, one people