Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Project Vector3 five times slower?

Author
Message
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 21st Aug 2007 20:47
Is it unusual for Project Vector3 to be five times slower when called from my dll than directly from DBP?

http://3dfolio.com
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Aug 2007 21:40
It would be unexpected - it should be the same speed or maybe a little faster. Make sure that you are only loading the function pointer once.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 21st Aug 2007 23:31 Edited at: 21st Aug 2007 23:41
Yea. I'm only calling ?ProjectVector3@@YAXHHHHH@Z. That's it.

Can you confirm if this is a problem in C++? I'm using PureBasic, though it should be just as fast.

This is my DBP code. I mirrored the Project3Dto2D in PureBasic but replaced the globals with static variables. It returns the result vector as an integer.



This is my PB function. All of my DBP calls are macros. There are no additional functions being called at all so it should be fast.



http://3dfolio.com
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Aug 2007 23:55
Is that Freddix's library you are using? It might be a good idea to ask him - I see nothing wrong in what you are doing there.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 22nd Aug 2007 00:33 Edited at: 22nd Aug 2007 00:45
I'm not using PurePlugin. I'm locating the function pointer by its name and then calling it.

CallCFunctionFast(GetFunction(#Library,"Function"),Param1,Param2)

I even tried moving the pointer lookup to the constructor instead of having it search for every call. It didn't help at all.

http://3dfolio.com
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Aug 2007 01:10
Ok, that example would be very slow indeed - it will do a lookup of the function pointer on every call.

Even if you stored the result of the lookup into a variable and used that, there's the overhead of the CallCFunctionFast function to consider.

Isn't there any way to call a function pointer directly in PureBasic, like there is in C++? That's the only way you are going to be able to make the call at full speed.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 22nd Aug 2007 18:53 Edited at: 22nd Aug 2007 18:53
I haven't found the source of the problem yet. Here is a link to my post on the PureBasic forums if you would like to see what they're saying.

http://www.purebasic.fr/english/viewtopic.php?p=207633#207633

http://3dfolio.com
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Aug 2007 19:42
Ok, I've read through that thread - The basic speed problem does seem to be that you are making a lookup each loop.

If I were you I'd concentrate on getting the function pointer stored in a global first, even if it means still doing the lookup within your function, and then either moving that lookup into a function that can be exported as the mangled C++ name of ReceiveCoreDataPtr (that would be ?ReceiveCoreDataPtr@@YAXPAX@Z - no return value, accepts a single void pointer), or if that's not possible, wrap the lookup in an IF statement so that lookup only takes place if the function pointer has a value of 0.

You might also consider firing an email to Freddix for advice - He's the PureBasic expert around here, not me :p

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Freddix
AGK Developer
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 22nd Aug 2007 19:59 Edited at: 22nd Aug 2007 20:08
EDIT : Ergh! Sorry I didn't carefully read your procedure.
I'm not sure but, it should be cool to include a message requester inside your procedure to be sure, it will setup the vectors only once.

You also shouldn't use MACRO(s).
I advice you to firstly setup all DarkBASIC Professionals command pointers for example :

Setup The DarkBASIC Professional commands this way :
Quote: "
Global MyPointer.l
Procedure AllSETUP()
If OpenLibrary( 1, "DBProBitmapExtends.dll")
MyPointer = IsFunction( 1 , "BMP_Init" )
CloseLibrary( 1 )
Endif
EndProcedure
"

Create wrapping commands using this method :
Quote: "
Procedure.l BMP_Init()
Retour.l = CallCFunctionFast( MyPointer )
ProcedureReturn Retour
EndProcedure
"

And use directly the commands from your plugin.
It should be faster.

MyPointer.l =

Gandalf said: "All we have to decide is what to do with the time that is given to us"
Odyssey-Creators - X-Quad Editor - 3DMapEditor
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 22nd Aug 2007 20:45 Edited at: 22nd Aug 2007 20:46
I would think your method to be slower. It's the same thing I'm doing but wrapped up in a procedure instead of a macro.

IanM, would you please confirm whether this is an issue in C++? The way I'm writing it should be the same.

Quote: "Isn't there any way to call a function pointer directly in PureBasic, like there is in C++? That's the only way you are going to be able to make the call at full speed."


Quote: "That's what CallCFunctionFast does."


Quote: "
CallCFunctionFast()

Syntax

Result = CallCFunctionFast(*FunctionPointer [,Parameter1 [, Parameter2...]])
Description

Calls a function directly, using its address. "


http://3dfolio.com
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Aug 2007 21:12
What Freddix is showing you is the way that netmaestro from the PB forum was suggesting in his 3rd post - a setup function, and then the actual function. It's what I suggested also in my last post.

The method I use in C++ appears to be identical (as far as I can tell) to netmaestro's second post



So that is create a function type (PB: Prototype), create a variable based on that type and populate it with the function address, then call the function by treating the variable as if it were a function.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 23rd Aug 2007 00:36 Edited at: 23rd Aug 2007 00:37
I tried to use a prototype instead. It only improved performance by 0.005 seconds. But in that case I had the function lookup still inside the function. I kept getting memory errors if I set it up outside the function and shared it or declared it as a global.

http://3dfolio.com
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 26th Aug 2007 06:51 Edited at: 26th Aug 2007 22:52
I've managed to get it down to 200% slower but that's it. IanM, can you confirm that this actually runs faster in C++?

http://3dfolio.com

Login to post a reply

Server time is: 2024-05-18 06:32:57
Your offset time is: 2024-05-18 06:32:57