Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

[SUGGESTION] Responsibility of keeping 'this' alive in script methods?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 GGLucas   Members   -  Reputation: 140

Like
0Likes
Like

Posted 16 November 2013 - 03:26 PM

I was trying to investigate why a trivial script method call was taking five times as long to execute as the equivalent trivial global function. It became obvious when I checked out the bytecode: every method starts with an AddRef() on the this pointer, and ends with a Release(). These are 'somewhat' expensive function calls handling atomics and such, and completely unnecessary in a large amount of cases.

 

It really feels like the caller should be responsible for keeping alive the object it's calling on, not the object itself. That way, the caller can make optimizations that would otherwise not be possible. Especially in our engine where many thousands of small methods are being called on script objects already held by the application code every frame, reducing the overhead of a method call seems like a useful thing to do.

 

After realizing that this behaviour was already in place for methods returning references, we tried to turn that behaviour on for all script method calls. The attached file is not so much a patch as this suggested change in behaviour. It's faster, better optimizable and more consistent - returning a reference no longer changes how the calling convention works. We've been using it for a little while.

 

It does mean the application needs to ensure objects it's calling methods on stay alive during those calls, which is added responsibility for application writers and a possible break in backwards compatibility, so not making this change is understandable as well. Maybe as an engine option?

 



Sponsor:

#2 GGLucas   Members   -  Reputation: 140

Like
0Likes
Like

Posted 16 November 2013 - 03:27 PM

Uploader was being annoying.

Attached Files



#3 Andreas Jonsson   Moderators   -  Reputation: 3444

Like
0Likes
Like

Posted 16 November 2013 - 03:54 PM

I will certainly look into this. Thanks for yet another patch. 


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#4 Andreas Jonsson   Moderators   -  Reputation: 3444

Like
0Likes
Like

Posted 24 May 2014 - 03:36 PM

I've included this patch in revision 1941.

 

Rather than putting the responsibility on the application to remember to keep a reference I added that in to the context. I'm still thinking on making this optional by adding an additional argument to asIScriptContext::SetObject where the application can tell the context that it doesn't need to increment the refcount.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS