Two ahk script vs Combined ahk script which is faster ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Two ahk script vs Combined ahk script which is faster ?

29 Nov 2015, 22:32

Hello everyone.

I got a stupid question, Two AHK Scripts v.s. Combined AHK Script.

Which one should be faster ?

I got 5 AHK Scripts working at the same time, it's important for me, Should I merge them up ?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Two ahk script vs Combined ahk script which is faster ?

29 Nov 2015, 22:59

It's not a straightforward answer. There are some instances, like here, where it may be more useful for the user to have separate scripts to achieve what they want. But if the scripts aren't intended to interact, I don't believe there is any significant impact on any scripts performance. The only possibility is if for some reason multiple AHK scripts can run on multiple threads, but I don't know if that's what actually happens. Otherwise I'd think I'd see that as a more common suggestion to accomplishing multithreading... AHK does pseudo-multithreading where a single thread goes back and forth between hotkey or other code executions.

Anyhow, I would say that the benefit of merged scripts is in turning them on and off. I have a single script that contains many functions I use daily, and some I use a few times in a week, all in one script that I have launched when my computer turns on. This makes it convenient for me. I do have dozens of other scripts I will turn on if I decide to work in program or on a project that is aided by those scripts. Some of those are combined scripts themselves - combined purely because they are intended for use on the same or similar programs. I also have a script that I have running constantly, but it's different from that first script I talked about. This latest script is my Test Script which I use to test code samples from the forums, and it comes with a nice Reload hotkey. I didn't want this part combined with my first script, because I didn't want to reload my first script often, which can work with temporary data which is lost on a reload. So I have a benefit of having two scripts with many different functions separated - one I want to keep running without interruption, the other I am totally fine with reloading many times a day.

Perhaps a dev will say where I am wrong in my understanding above - which is totally possible to be incorrect - or other users can chime in with their instances of combining or separating scripts.

Overall, for your question, I don't think there's any performance improvement you will fine with merging your scripts. It will be up to your personal preference if you want to combine the scripts. If you do merge the scripts, be careful of any directives (like #If) you have, or if any hotkeys or commands at the end of a script lack a return command.
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Re: Two ahk script vs Combined ahk script which is faster ?

01 Dec 2015, 07:02

Exaskryz wrote:It's not a straightforward answer. There are some instances, like here, where it may be more useful for the user to have separate scripts to achieve what they want. But if the scripts aren't intended to interact, I don't believe there is any significant impact on any scripts performance. The only possibility is if for some reason multiple AHK scripts can run on multiple threads, but I don't know if that's what actually happens. Otherwise I'd think I'd see that as a more common suggestion to accomplishing multithreading... AHK does pseudo-multithreading where a single thread goes back and forth between hotkey or other code executions.

Anyhow, I would say that the benefit of merged scripts is in turning them on and off. I have a single script that contains many functions I use daily, and some I use a few times in a week, all in one script that I have launched when my computer turns on. This makes it convenient for me. I do have dozens of other scripts I will turn on if I decide to work in program or on a project that is aided by those scripts. Some of those are combined scripts themselves - combined purely because they are intended for use on the same or similar programs. I also have a script that I have running constantly, but it's different from that first script I talked about. This latest script is my Test Script which I use to test code samples from the forums, and it comes with a nice Reload hotkey. I didn't want this part combined with my first script, because I didn't want to reload my first script often, which can work with temporary data which is lost on a reload. So I have a benefit of having two scripts with many different functions separated - one I want to keep running without interruption, the other I am totally fine with reloading many times a day.

Perhaps a dev will say where I am wrong in my understanding above - which is totally possible to be incorrect - or other users can chime in with their instances of combining or separating scripts.

Overall, for your question, I don't think there's any performance improvement you will fine with merging your scripts. It will be up to your personal preference if you want to combine the scripts. If you do merge the scripts, be careful of any directives (like #If) you have, or if any hotkeys or commands at the end of a script lack a return command.
Nice answer . Totally agree !
But one more little question from me.
Why "function" and "#Include" is slow in AHK?

e.g You can save series of Script.
A.ahk include B.ahk,and B.ahk include C.ahk, ... and the Y.ahk call Z.ahk's function.

It make the CALL sooooo....soooo....slow.even I can realize there's some "DELAYs" before the CALL.
<What if there is a lib only need for Main script, maybe better yank it into the Main Script for better performance ?>
and you can give it a TRY.
Pack a "AHK function" into a "function" and CALL it times, it looks like the Script took too much time on JMP ?


Thanks ! and by the way... deeply sorry about my horrible English loool...I'll try my best to improve any you couldnt understand.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Two ahk script vs Combined ahk script which is faster ?

01 Dec 2015, 07:43

If in their own script file each script will have its own process aka a way of multithreading

but this way opens you up a few issues like having the same hotkey defined multiple times but only the last will work in each context

To the other thing

As i know it the autohotkey interpreter parses and reads in every #include in the spot it is encountered it in the script file aka putting the function definition in that place in your main script

I did a test on a small scale 25 nested includes but it did not take any longer to call a function that way then just having the function in the same script file in the first place

and there was absolutely no noticeable delay at all

please post all of you code that shows this delay so we may help you remove or see what may curse it.
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Re: Two ahk script vs Combined ahk script which is faster ?

06 Dec 2015, 20:57

Blackholyman wrote:If in their own script file each script will have its own process aka a way of multithreading

but this way opens you up a few issues like having the same hotkey defined multiple times but only the last will work in each context

To the other thing

As i know it the autohotkey interpreter parses and reads in every #include in the spot it is encountered it in the script file aka putting the function definition in that place in your main script

I did a test on a small scale 25 nested includes but it did not take any longer to call a function that way then just having the function in the same script file in the first place

and there was absolutely no noticeable delay at all

please post all of you code that shows this delay so we may help you remove or see what may curse it.
I agree about the #include command may not make the Script slower, but how about why the customize function is slower than built-in function ?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], Xaucy and 158 guests