Very high call overhead to a specific C++ object member function

71 views
Skip to first unread message

Stuart Allen

unread,
Sep 11, 2012, 1:19:36 AM9/11/12
to v8-u...@googlegroups.com
Hi,

I stumbled across a very strange problem. I'm using 3.12.19.1 on Linux 64-bit.

I have an object implemented in C++, I noticed an unexpected slow-down and eventually traced it to a particular call.

If the object method is called like this:

this.MyObject.method() 

it takes 20ms (milliseconds) to execute, when it should be 0ms. I made timings inside C++ and they show a total 0ms execution time so the 20ms is introduced inside the JS<->C++ boundary.

On a hunch I tried this:

var cn= this.MyObject.method;
 
cn(); 

and guess what, it takes 0ms!! 

methods of the same Object instance are called before and after yet they execute as expected with no measurable overhead (in millsecond land). 

Is there any foundation for such a problem? Could it be a scoping/resolving issue causing problems resolving the method?

Are there any diagnostics that could help here?

Thanks,

Stuart.

Matthias Ernst

unread,
Sep 11, 2012, 2:45:45 AM9/11/12
to v8-u...@googlegroups.com
On Tue, Sep 11, 2012 at 7:19 AM, Stuart Allen <stu...@lttlrck.com> wrote:
> Hi,
>
> I stumbled across a very strange problem. I'm using 3.12.19.1 on Linux
> 64-bit.
>
> I have an object implemented in C++, I noticed an unexpected slow-down and
> eventually traced it to a particular call.
>
> If the object method is called like this:
>
> this.MyObject.method()
>
>
> it takes 20ms (milliseconds) to execute, when it should be 0ms. I made
> timings inside C++ and they show a total 0ms execution time so the 20ms is
> introduced inside the JS<->C++ boundary.
>
> On a hunch I tried this:
>
> var cn= this.MyObject.method;
> cn();

For the record, this call has different semantics: it won't pass
MyObject, but rather the global object, as "this". Not that that would
immediately explain the timing difference you see.

I think you may need to post some more context code.
Especially regarding the construction of "MyObject" including "method".

Is the timing you see measured as an average of many loop iterations
or just one call?

Matthias

>
>
> and guess what, it takes 0ms!!
>
> methods of the same Object instance are called before and after yet they
> execute as expected with no measurable overhead (in millsecond land).
>
> Is there any foundation for such a problem? Could it be a scoping/resolving
> issue causing problems resolving the method?
>
> Are there any diagnostics that could help here?
>
> Thanks,
>
> Stuart.
>
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users

Stuart Allen

unread,
Sep 11, 2012, 11:24:39 AM9/11/12
to v8-u...@googlegroups.com
My C++ time stamp resolution was misleading. All is well after all. I should have known it was me and sending the mail late was a bad omen.

Sorry for wasting your time.

Stephan Beal

unread,
Sep 13, 2012, 6:46:58 AM9/13/12
to v8-u...@googlegroups.com
On Tue, Sep 11, 2012 at 5:24 PM, Stuart Allen <stu...@lttlrck.com> wrote:
My C++ time stamp resolution was misleading. All is well after all. I should have known it was me and sending the mail late was a bad omen.

Sorry for wasting your time.

FWIW this _was_ actually a problem in some early v8 version (several years ago), and subsequent optimizations closed the gap between member and non-member calls. i don't have the ticket number handy (and it doesn't really matter any more), but there was actually a time where the difference between member and non-member calls was tremendous.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
Reply all
Reply to author
Forward
0 new messages