Sign in to follow this  
Followers 0
Yusuke

Slow Message Loop?

2 posts in this topic

Hi,

I have a main script with an embedded IE control.

Code is like this :

#include <GUIConstants.au3>
#include <IE.au3>

_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
$Gui = GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 10, 640, 360)
$GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
$GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
$GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
$GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)

GUICtrlSetResizing($GUIActiveX, $GUI_DOCKTOP)

GUISetState()     ;Show GUI

_IENavigate ($oIE, "about:blank")

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            _IENavigate ($oIE, "about:blank")
        Case $msg = $GUI_Button_Back
            
            $oBody = _IETagNameGetCollection($oIE, "body", 0)
            
            Local $i
            For $i = 0 To 10
                _IEDocInsertHTML($oBody, "<b>Hello</b><br>")
            Next
            
             $iVisibleHeight = $oIE.document.body.clientHeight
            $oIE.document.parentwindow.scrollBy(0,$iVisibleHeight)
    
        Case $msg = $GUI_Button_Forward
            _IEAction ($oIE, "forward")
            MsgBox(64, "Test", _IEDocReadHTML($oIE))
        Case $msg = $GUI_Button_Stop
            _IEAction ($oIE, "stop")
    EndSelect
WEnd

GUIDelete()

Exit

If you click the back button, it will write then times "Hello" in bold.

So far, no problem and it does this quickly.

Now, I need a second script to interact with the GUI of the main script, and write things to the IE control of this window (I plan to use IE like a console and display logs stuff in there).

Code of this second script is like this :

#include <IE.au3>

$oIE = _IEAttach("Embedded Web control Test", "embedded")
;$oIE = _IEAttach("about:blank", "embedded")

$oBody = _IETagNameGetCollection($oIE, "body", 0)

Local $i
For $i = 0 To 10
    _IEDocInsertHTML($oBody, "<b>Hello</b><br>")
Next

Which is supposed to write Hello ten times to the IE control in main window if you run them side by side, which it indeed does.

The problem is that the insertions made by the second script are very slow while the ones made on the main script are instantaneous.

I thought it was something with the IE.au3 library perhaps, like a parameter to set, but after having checked the source code, I couldn't find anything strange.

I used the second script against a real IE window that I first navigated manually to about:blank, and there the insertions were instantaneous.

So, I wonder if the problem doesn't come from the message loop which may be not fast enough and may be why the insertions seem slow.

Can you confirm it is so ? I am rather new to AutoIt (I did some C/Win32 in the past though) and do not know it is limitations yet. And if so, how can I speed it up. Event Mode GUI seems even worse.

Any trick or advice is very welcome.

Thanks in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well, after one night, I got the idea to make some benchmarking using the DllCall function and GetTickCount API function which returns the number of milliseconds since the system has started. By calling it twice at different spots and making the difference, you can roughly estimate how long a part of code takes to execute.

I ran it on my message loop/GUIGetMsg loop and I got 0 ms with occasionnals 16 ms, which seems to indicate that the message loop isn't the culprit.

I then ran it inside the _IEDocInsertHTML function of the IE3.au3 header and the results are surprising.

Here is the code

Func _IEDocInsertHTML(ByRef $o_object, $s_string, $s_where = "beforeend")

    Local $iTicksBegin = DllCall("kernel32.dll", "long", "GetTickCount")

    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEDocInsertHTML", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    If Not __IEIsObjType($o_object, "browserdom") Or __IEIsObjType($o_object, "documentcontainer") Or __IEIsObjType($o_object, "document") Then
        __IEErrorNotify("Error", "_IEDocInsertHTML", "$_IEStatus_InvalidObjectType", "Expected document element")
        SetError($_IEStatus_InvalidObjectType, 1)
        Return 0
    EndIf
    
    Local $iTicksEnd = DllCall("kernel32.dll", "long", "GetTickCount")
    
    FileWriteLine("ticks.txt", $iTicksEnd[0] - $iTicksBegin[0])

    Local $iTicksBegin = DllCall("kernel32.dll", "long", "GetTickCount")

    $s_where = StringLower($s_where)
    Select
        Case $s_where = "beforebegin"
            $o_object.insertAdjacentHTML ($s_where, $s_string)
            SetError($_IEStatus_Success)
            Return 1
        Case $s_where = "afterbegin"
            $o_object.insertAdjacentHTML ($s_where, $s_string)
            SetError($_IEStatus_Success)
            Return 1
        Case $s_where = "beforeend"
            $o_object.insertAdjacentHTML ($s_where, $s_string)
            SetError($_IEStatus_Success)
            
;           Local $iTicksEnd = DllCall("kernel32.dll", "long", "GetTickCount")
;           FileWriteLine("ticks.txt", $iTicksEnd[0] - $iTicksBegin[0])
            Return 1
        Case $s_where = "afterend"
            $o_object.insertAdjacentHTML ($s_where, $s_string)
            SetError($_IEStatus_Success)
            Return 1
        Case Else
    ; Unsupported Where
            __IEErrorNotify("Error", "_IEDocInsertHTML", "$_IEStatus_InvalidValue", "Invalid where value")
            SetError($_IEStatus_InvalidValue, 3)
            Return 0
    EndSelect
    
EndFunc ;==>_IEDocInsertHTML

I've benchmarked two parts of this function, the first part being the part before the cases and then the one after.

When running it from my child script, I guess these times (in milliseconds) for each call :

First part (beginning of function up to Select)

328

312

328

344

344

281

391

328

312

359

344

Second part of the code (Select -> beforeend)

16

31

16

31

31

32

31

15

31

16

31

While the times on the second part of the function aren't stellar, the first part seems slow since this part for each call takes 1/3 of seconds (on a Dual Core 2.3 GHz).

What's surprising, is that it only happens when running it from my second script.

If run this function from the main script, I get 0 ms for most calls !

I'm very confused by this problem and it is really weird.

I tried the same with a listbox (adding items from my second script to a listbox created from a "main" script) and the items get added quickly enough, so it seems to be related to the IE library.

Can somebody please help ?

Thanks in advance;

Edited by Yusuke

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0