swtsvn wrote:Thanks Cherno,
Do you mean, everytime a new browser/tab (CefBrowserHost::CreateBrowser) is created, it would call OnContextCreated(), and attach the functions to the window of the browser, thereby using more twice the memory for those functions, if there are two browsers in total?
Which would mean onWebKitInitialized would be called only once through the lifespan of the application, irrespective of the total browsers/tabs created, and all of then can acccess the native functions, and there will be only one set of memory alloted for these functions, thereby saving memory?
Or something else? Can you elaborate on "on a non permanent basis"?
I don´t have the knowledge about CEF or Chrome V8 internals in order to evaluate the memory cost/savings of extensions vs functions, but I assume that extensions also take memory per browser for each of the functions registered at the browser "window" context. If is there any memory saving by not manually registering the functions at OnContextCreated, it might be small. In my limited knowledge, the benefit I get with the extension is having a common API registered without much effort (function registering and handling is harder to manage, due to the multiprocess nature of CEF/Chrome).
I can´t imagine a case where you would register thousands of functions so the cost would be a burden, but maybe your needs are different than mine.
In order to decrease (a lot) the amount of functions I need outside of the common api, I use async messages with success/fail callbacks back to javascript. I find it much easier to maintain than registering functions. I only use functions if I really need a synchronous answer, but I try to avoid it as much as possible, as async calls don´t block the render process and are easier to transform to standard xhr calls if I ever use that code on a web server.