Jump to content

Slow UDF Performance


Recommended Posts

I have a very simple UDF, which contains a few "helper" functions, like the one below (_getNetworkDrive).  I notice that when I call this function from my main script, which is approaching 3000-lines of code (big & some what complex), the performance of the UDF function _getNetworkDrive is very slow as compared to when I call the same function from a simple test script.  I do not have any different processing happening (e.g., launching another script) between the BIG script and the small test script.  I also confirmed that the CPU & memory are nominal (not significantly different from the test script) when the BIG script is running the _getNetworkDrive function.

To quantify the performance hit, I ran several times with the test script and see that the function takes about 30-mSec, with a few peaks near 300-mSec.  The same function/UDF called from the BIG script takes anywhere from 1-second (on the low end) to as much as 16-seconds!  So, we're talking about 2-3 orders of magnitude difference.  The majority of processing time seems to be in the For/Next loop that is iterating through the drives.  I suspect that the culprit is the FileExists($drive) conditional check, but I cannot understand why that would be the case when called from a larger script.

Any ideas of why the UDF function's performance would suffer  when part of a larger script?

 

zc?&R6?73?&?46?FR&WGG?&??B??r?WF??B#?ФgV?2?vWD?WGv?&?G&?fR??Р???FW&FRF?&?Vv?F?R?WGv?&?G&?fW0Р?FG&?fTFWF??2?b33???LJ???'&?6?gG?6??54??Feuuu&??Bb33??Р?FG&?fW2?G&?fTvWDG&?fR?b33???WGv?&?b33???Р??bT&?V?B?FG&?fW2?fwC??"F?V?Р??f?"F??F?FG&?fW5??Р???FG&?fR?FG&?fW5?F??Р????b7G&??t??7G"?G&?fT?vWB?FG&?fR??FG&?fTFWF??2??Bf??TW??7G2?FG&?fR?F?V?Р????&WGW&?FG&?fPР???V?D?`Р???W?@Р?V?D?`РР????G&?fRf?V?B?GFV?BF??Р?FG&?fR?G&?fT?FB?b33???b33???FG&?fTFWF??2??G6gG7W6W"?G6gG772?Р??b??BFG&?fRF?V?&WGW&?6WDW'&?"????b33???WGv?&?G&?fR?b33??f??FG&?fTFWF??2f??b33???6?V?B??B&R?VBb33???РФV?DgV?2??vWD?WGv?&?G&?fR????&S???

 

Link to comment
Share on other sites

  • Developers

Not sure what the last couple of line are, or should that be the UDF you are referring to?
I can't imagine why there would be a significant difference either between a large and small script using the same UDF.
Maybe you can insert some consolewrite statements showing the actual time it takes in the different scenario's.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Can you at least post the _getNetworkDrive function (maybe it's the unreadable lines at the end of your post)?
Maybe your code runs into some kind of timeout when checking for a non existing network drive?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

How weird, I posted the code in the original posting using the <> (code) tool.  I'll try again here.

Jos, the times I was reporting were from a consolewrite of TimerInit & TimerDiff portions built into the function.  Hopefully, you can see that below.

Func _getNetworkDrive()
$t1 = TimerInit()
    ; Iterate through the network drives
    $driveDetails = '\\xxx.brickftp.com@SSL\DavWWWRoot'
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $driveDetails = ' & $driveDetails & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    $drives = DriveGetDrive('Network')
    If UBound($drives)>=2 Then
        For $i=1 To $drives[0]
            $drive = $drives[$i]
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $drive = ' & $drive & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            If StringInStr(DriveMapGet($drive), $driveDetails) And FileExists($drive) Then
                ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($t1) = ' & TimerDiff($t1) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                Return $drive
            EndIf
        Next
    EndIf

    ; No drive found, attempt to map
    $drive = DriveMapAdd('*', $driveDetails, 1,  $sftpCpUser, $sftpCpPass)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($t1) = ' & TimerDiff($t1) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    If Not $drive Then Return SetError(-1, 0, 'Network drive (' & $driveDetails & ') could not be mapped')

EndFunc ; _getNetworkDrive()

 

Link to comment
Share on other sites

Well, I guess I just needed to "verbalize" the problem...I traced the issue to another UDF include (VirtualFlex.Memory.au3 by @prazetto), which apparently is causing the SIGNIFICANT slow-down.  I only use this UDF in one place and could probably do without.  So, in the absence of time to investigate, I am going to remove that dependency.  In doing so, the BIG script now returns the _getNetworkDrive function in a few milliseconds.  I suspect the VirtualFlex.Memory.au3 UDF virtualization causes the slow-down maybe @prazetto could investigate the issue?

 

Edited by bobmcrae
spelling
Link to comment
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
 Share

×
×
  • Create New...