News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

slow loading program

Started by jimg, February 19, 2018, 06:39:12 AM

Previous topic - Next topic

jimg

I have a program I've used for a decade that suddenly started taking over 3 seconds to load.  Previously it loaded nearly instantaneously.
I use is a lot, so it was really bugging me.  After a couple of hours of sticking in test points, I found the area that was now causing the problem.
I'm assuming it's some recent update to windows defender that was the real culprit.

The code in question just does some setup for two richedit controls.

The original code looked like this.

mov hFont,eax
m2m tmp,hEText1
SetupRichEdit:
mov cf.cbSize,0
    inv SendMessage, tmp, EM_GETCHARFORMAT, 0, addr cf
    mov cf.crBackColor, 189 shl 16 or 220 shl 8 or 235 ;rgb(235,220,189)
mov cf.cbSize,sizeof cf
    mov cf.dwMask,CFM_COLOR or CFM_BACKCOLOR
    inv SendMessage, tmp, EM_SETCHARFORMAT, SCF_ALL, addr cf
    .if hFont!=0
inv SendMessage,tmp,WM_SETFONT,hFont,TRUE
.endif
    inv  SendMessage,tmp,EM_SETTEXTMODE,TM_PLAINTEXT,0
    ; subclass the rich edit controls so we can get the tab key
    inv SetWindowLong,tmp,GWL_WNDPROC,EditWndProc
mov OldEditWnd,eax ; save old routine

mov eax,tmp
.if eax==hEText1
m2m tmp,hEText2
jmp SetupRichEdit ; do other box also
.endif


Not very sophisticated or tricky, just loop through with each handle.

By unrolling the loop thusly:

mov hFont,eax
mov cf.cbSize,0
    inv SendMessage, hEText1, EM_GETCHARFORMAT, 0, addr cf
    mov cf.crBackColor, 189 shl 16 or 220 shl 8 or 235 ;rgb(235,220,189)
mov cf.cbSize,sizeof cf
    mov cf.dwMask,CFM_COLOR or CFM_BACKCOLOR
    inv SendMessage, hEText1, EM_SETCHARFORMAT, SCF_ALL, addr cf
    .if hFont!=0
inv SendMessage,hEText1,WM_SETFONT,hFont,TRUE
.endif
    inv  SendMessage,hEText1,EM_SETTEXTMODE,TM_PLAINTEXT,0
    ; subclass the rich edit controls so we can get the tab key
    inv SetWindowLong,hEText1,GWL_WNDPROC,EditWndProc
mov OldEditWnd1,eax ; save old routine


mov cf.cbSize,0
    inv SendMessage, hEText2, EM_GETCHARFORMAT, 0, addr cf
    mov cf.crBackColor, 189 shl 16 or 220 shl 8 or 235 ;rgb(235,220,189)
mov cf.cbSize,sizeof cf
    mov cf.dwMask,CFM_COLOR or CFM_BACKCOLOR
    inv SendMessage, hEText2, EM_SETCHARFORMAT, SCF_ALL, addr cf
    .if hFont!=0
inv SendMessage,hEText2,WM_SETFONT,hFont,TRUE
.endif
    inv  SendMessage,hEText2,EM_SETTEXTMODE,TM_PLAINTEXT,0
    ; subclass the rich edit controls so we can get the tab key
    inv SetWindowLong,hEText2,GWL_WNDPROC,EditWndProc
mov OldEditWnd1,eax ; save old routine


The load time was back to near instantaneous.

Odd.

ragdog

Hello Jimg

Can you post both examples to test it?

Mfg,

jimg

Let me take a look.   I doubt it would happen in a small program but I'll give it a try when I get a chance.  I only posted this to give hope to someone else that has a program that was slow to load and didn't think it could be fixed. 

jimg

#3
Here it is as stripped down as I could make it.

Uncomment the first line to use the new code, or leave it commented to use the old slow loading code.

Note:  I would not be supprised to find it works differently on someone else machine with a different amount of memory, etc.

edit:  removed program, see much smaller version below.

ragdog

Hi

I have test your code with
trynewcode=1    ; uncomment this line to try the new code

and without trynewcode flag,

I cannot see any differrent is loading fast or slow.

Test on Win7 x64


Regards,

jj2007

Same for me, Win7-64 with Windows Defender ON.

We had a similar case some time ago:
Quote from: clamicun on December 04, 2015, 04:03:17 AM
Testing your Split$ Macro.
Yes it does the job, but why does it take about 10 seconds the first time ?
Then it works normally.

jimg

I just tested on five different computer with the same result, 3-6 seconds load time on the old exe.   Granted, these are all windows 10 64bit.

Here's the two exe's I used in case it's an assembler problem.  These were made with uasm, but got the same results with masm 6.15

LordAdef

Sorry jimg for a quick hijack:

I loved your "inv" thing! Respectfully, I´m stealing it!

jimg

You're welcome.   I've been using it for twenty years, so I don't remember where I got it from originally.

jimg

#9
And, as if you all weren't sick of this already, here is the code stripped down to the minimum that shows the problem.  The slow code now take 4.5 seconds to load on my computer.

edit: replaced with even smaller code.

jj2007

Hi Jim,

I tested it on my ladies' Win10 machine. It took some time, though - 22 seconds for the slow version.
And it definitely is the fault of Window Defender: once I disactivated real time protection, your exe loads normally.

You might try this link, although the option does not exist on my Win10 machine.

As written earlier, normal loading on Win7-64 even with defender activated.

jimg

Thank you for the confirmation, I was beginning to wonder.

And thanks for the link on how to add exclusions, that will come in handy as I have several other slow loading programs :)