Passing vector<double> over to Javascript

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Passing vector<double> over to Javascript

Postby joelhnatow » Wed Apr 01, 2015 3:42 pm

Hi,

I'm working on a project where in my C++ native app I'm going to be passing over a vector<double> with roughly ~10,000 to ~20,0000 doubles in it to my Javascript layer, which in turns expects a Javascript array. I see two options now to get that data over there - convert that vector to a string and just simply call ExecuteJavascript() (and then JSON.Parse() it) or use CefV8Value::CreateArray and then populate the array with CefV8Value::CreateDouble for each double in the vector and then use SetValue() to set it to the window object. My questions are 1) is there any other (better) way to get this data to the JS side and 2) if not is there any real performance benefit from using the native JS types that CEF provides over just pumping big strings in via ExecuteJavascript()?

Thanks!
joelhnatow
Newbie
 
Posts: 6
Joined: Wed Apr 01, 2015 3:24 pm

Re: Passing vector<double> over to Javascript

Postby magreenblatt » Thu Apr 02, 2015 3:14 am

joelhnatow wrote:is there any real performance benefit from using the native JS types that CEF provides over just pumping big strings in via ExecuteJavascript()?

Sounds like something that would be easy to benchmark. Maybe you can tell us which is better :).
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Passing vector<double> over to Javascript

Postby joelhnatow » Thu Apr 02, 2015 7:00 am

:D Fair enough, I will do that! Did I miss any other method (short of using websockets or something somewhat external to CEF) to get data like this from point A to point B?
joelhnatow
Newbie
 
Posts: 6
Joined: Wed Apr 01, 2015 3:24 pm

Re: Passing vector<double> over to Javascript

Postby magreenblatt » Thu Apr 02, 2015 7:07 am

joelhnatow wrote::D Fair enough, I will do that! Did I miss any other method (short of using websockets or something somewhat external to CEF) to get data like this from point A to point B?

You could use a custom resource handler to return the JSON via the network stack. See https://bitbucket.org/chromiumembedded/ ... t-handling
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Passing vector<double> over to Javascript

Postby joelhnatow » Fri Apr 10, 2015 9:48 am

magreenblatt wrote:
joelhnatow wrote::D Fair enough, I will do that! Did I miss any other method (short of using websockets or something somewhat external to CEF) to get data like this from point A to point B?

You could use a custom resource handler to return the JSON via the network stack. See https://bitbucket.org/chromiumembedded/ ... t-handling


Unfortunately I didn't follow how this would be able to get this data from the native C++ app over to JS-land...

However, for anyone who is curious, from my testing/benchmarking, it appears that just converting the vector<double> to a huge JSON string and calling ExecuteJavaScript() in my C++ app is ~2x faster vs. converting everything to Cef ListValue types/sending an IPC message/converting to CefV8Value/passing over to the JS world.

This came in handy to optimize the conversion from double-string - https://github.com/miloyip/dtoa-benchmark

HTH someone / Thanks for the help!
joelhnatow
Newbie
 
Posts: 6
Joined: Wed Apr 01, 2015 3:24 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 104 guests