Ahkdll load time

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Ahkdll load time

Post by arcticir » 30 Jan 2020, 06:31

In the latest version of H2, I tested the load time of ahkdll-an average time of 30MS
I remember that in an update, the load time was reduced to about 10MS.
Where did it change?

=======

NewThread also seems to have changed. At its fastest, it was about 6MS, now it is 60MS.
MsgBox NewThread("MsgBox ahktime(" ahktime() ")")

Code: Select all

r:=ahkdll()

MsgBox r.new("MsgBox ahktime(" ahktime() ")")

ahkdll(){
	static dll:=(UnZipRawMemory(LockResource(hr:=LoadResource(0,s:=FindResource(0,"F903E44B8A904483A1732BA84EA6191F",10))),SizeofResource(0,s),dll),FreeResource(hr),dll)
	return (t:=CriticalObject(),
		t.%""%:=r:=MemoryLoadLibrary(&dll),
		t.DefineMethod("func",DynaCall(MemoryGetProcAddress(r,"ahkFunction"),"s==sssssssssss")),
		t.DefineMethod("post",DynaCall(MemoryGetProcAddress(r,"ahkPostFunction"),"i==sssssssssss")),
		t.DefineMethod("new",DynaCall(MemoryGetProcAddress(r,"ahktextdll"),"ut==sss")),
		t.DefineMethod("add",DynaCall(MemoryGetProcAddress(r,"addScript"),"ut==si")),
		t.DefineMethod("exec",DynaCall(MemoryGetProcAddress(r,"ahkExec"),"ut==sui")),
		t.DefineMethod("get",DynaCall(MemoryGetProcAddress(r,"ahkgetvar"),"s==sui")),
		t.DefineMethod("set",DynaCall(MemoryGetProcAddress(r,"ahkassign"),"ui==ss")),
		t.DefineMethod("sub",DynaCall(MemoryGetProcAddress(r,"ahkLabel"),"ui==sui")),
		t.DefineMethod("pause",DynaCall(MemoryGetProcAddress(r,"ahkPause"),"i==s")),
		t.DefineMethod("exit",DynaCall(MemoryGetProcAddress(r,"ahkTerminate"),"i==i")),
		t.DefineMethod("ready",DynaCall(MemoryGetProcAddress(r,"ahkReady"),"")),
		t.DefineMethod("reload",DynaCall(MemoryGetProcAddress(r,"ahkReload"),"i==i")),t)
}
ahkTime(s:=0,i:=6){
	static r:=(QueryPerformanceFrequency(getvar(r:=0)),r)
	QueryPerformanceCounter(getvar(n:=0))
	if !i
	{
		p:=s/1000*r,n2:=n,c:=A_IsCritical,Critical("on")
		if s>15
			sleep(((s-5)//15)*15)
		while ((n2-n)<p)
			QueryPerformanceCounter(getvar(n2:=0))
		Return (Critical("c"),Round((n2-n)/r, 6))
	}
	Return (s ? Round((n-s)/r, i) : n)
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 30 Jan 2020, 16:17

Do you remember which version was faster?
Can you check if MemoryLoadLibrary(..., t.DefineMethod(... or .new(... is causing the delay?
Also it would be good to test it in a loop to get a better average.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 31 Jan 2020, 03:06

I did not find the exact version. Aside from DLLs with uncertain parameters, look only at TLS. Its loading process is simpler than DLL, so its loading time has always been less than DLL, which I am pretty sure.
But now TLS has twice the load time of DLL, isn't this unreasonable?

==============

It seems that "#NoTrayIcon" has a huge impact on load time:

Code: Select all

	t:={}
	loop 10
		NewThread("#NoTrayIcon`nt:=CriticalObject(" (&t) ")`nt." a_index ":=ahktime(" ahktime() ")")
	,sleep(100)

MsgBox ov(t)
{
1 : 0.011854,
10 : 0.029145,
2 : 0.025184,
3 : 0.033740,
4 : 0.024284,
5 : 0.024960,
6 : 0.022160,
7 : 0.022076,
8 : 0.021882,
9 : 0.010828
}

Code: Select all

	t:={}
	f:=ahkdll()
	loop 10
	f.new("#NoTrayIcon`nt:=CriticalObject(" (&t) ")`nt." a_index ":=ahktime(" ahktime() ")")
	,sleep(100)

MsgBox ov(t)
{
1 : 0.015106,
10 : 0.028360,
2 : 0.026360,
3 : 0.027914,
4 : 0.028662,
5 : 0.015628,
6 : 0.027105,
7 : 0.026757,
8 : 0.027468,
9 : 0.026104
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 31 Jan 2020, 03:08

There were no changes in TLS, so it might be os or av related!
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 31 Jan 2020, 03:37

Yes, sorry, TLS has not changed.

=====

type () can't seem to judge the object wrapped by CriticalObject (), can we change its name? E.g. type(CriticalObject([])) = "Critical_array"
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 31 Jan 2020, 03:45

Also, array () does not seem to work in a multithreaded environment.


Code: Select all

	t:=CriticalObject([])
	f:=ahkdll()
	loop 10
	f.new("#NoTrayIcon`nt:=CriticalObject(" (&t) ")`nt.push(ahktime(" ahktime() "))")
	,sleep(100)

M ov(t)

Code: Select all

Error: CONTINUABLE EXCEPTION_ACCESS_VIOLATION

Mouse and Keyboard hooks have been disabled.

  -  Press yes to exit thread and continue execution.
  -  Press no to continue thread (debug).
  -  Press cancel to exit application.

Exception was caused in thread id: 11524
Line: 3
Specifically: .push(ahktime(4288125755605))
LineFile: #NoTrayIcon
t:=CriticalObject(53004344)
t.push(ahktime(4288125755605))
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 31 Jan 2020, 09:59

Regarding "IsBOM", if you ignore the second parameter, can you directly return the value it matches?

MsgBox IsBOM(&st,"utf-8")?"utf-8":IsBOM(&st,"utf-16")?"utf-16":....
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 31 Jan 2020, 16:41

This is fixed now.
IsBom will now return BOM if second parameter is omitted.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 31 Jan 2020, 17:27

Thank you.

By the way, MAP also has this problem.
Is there no need to change the type name of CriticalObject?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 31 Jan 2020, 18:17

Map is fixed now.
I think Type should report the correct object since CrticalObject is only a shell.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 31 Jan 2020, 22:00

try it:

t:=CriticalObject(map(CriticalObject({"a":"b"}),CriticalObject([1])))
MsgBox size:=ObjDump(t,var)
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 01 Feb 2020, 06:13

This is fixed now, thank you.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 01 Feb 2020, 18:53

But I still don't know how to for CriticalObject. Can you provide an example?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 02 Feb 2020, 05:00

You mean like that:

Code: Select all

t:=CriticalObject(map(CriticalObject({"a":"b"}),CriticalObject([1])))
MsgBox size:=ObjDump(t,var)
o:=objLoad(&var)
for k,v in o {
  If IsObject(k){
    for k,v in Type(k)="Object"?k.OwnProps():k
      MsgBox k "=" v
  }
  if IsObject(v){
    for k,v in Type(v)="Object"?v.OwnProps():v
      MsgBox k "=" v
  } else MsgBox k "=" v
}
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 02 Feb 2020, 06:23

no. I need obj to json. To be precise, I need to know the exact type of the object wrapped by CriticalObject.

Code: Select all

for i,n in t:=CriticalObject(map(CriticalObject({"a":"b"}),CriticalObject([1])))
{
;CriticalObject -> array? object? map?
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 02 Feb 2020, 07:16

Type(CriticalObject) will now report the type of wrapped object.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 02 Feb 2020, 07:52

thanks.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 02 Feb 2020, 14:15

ObjDump-objLoad has excellent performance. Do you think it is necessary to use them to improve "ahkFunction-ahkPostFunction" function? It can avoid their various disadvantages and limitations.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Ahkdll load time

Post by HotKeyIt » 02 Feb 2020, 17:11

You mean to wrap the parameters?
How would that be better than using an object directly?
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Ahkdll load time

Post by arcticir » 02 Feb 2020, 22:11

I'm not sure which "object" you are talking about
ThreadObj.func("test","1") or ThreadObj.test(1) ;base.__call
But obviously both have big flaws.
So I use the example of passing data between processes in the "OnMessage ()" document, passing "ObjDump-objLoad" binary data between processes.
It can safely pass data between TLS-DLL-EXE, it can pass objects, return objects; it can make optional parameters take effect; it does not cause errors by passing 1 (instead of "1")
I usually use this custom function more, but I still hope that the built-in functions can achieve the same function with similar principles.
Post Reply

Return to “AutoHotkey_H”