[Development] QML, v8 and freezing the global object

Thomas McGuire thomas.mcguire at kdab.com
Fri Oct 12 15:15:30 CEST 2012


On Friday 12 October 2012 13:30:57 Thomas McGuire wrote:
>  I've also been thinking about adding the frozen global object to the
> snapshot, but I think that will not work. Qt changes the global object, for
> example by adding the qsTr() function, so freezing would have to happen
> after Qt is done modifying the object. This is however not possible
> because the global object then refers to the address of the C++ function
> for qsTr(). That address can change on each invocation due to address
> space randomization and other factors, so it is not possible to keep a
> persistent snapshot. Snapshotting in v8 works because AFAIK the built-in
> functions there are all pure JS.

after investigating this, it turns out to not be JS all the way down. Instead, 
JS code can call into built-in runtime functions. These functions are static 
and listed in a big table. When serializing and deserializing the snapshot, 
references to built-in runtime functions are taken into account and encoded as 
an ID that is persistent across restarts.

So one idea to avoid the 100ms penalty of freezing the global object is to 
create the v8 snapshot after we've modified the global object and frozen it. 
That means we need add hooks in v8 that allow extending the built-in runtime 
function table with the functions we add to the global object. Once that is 
done, creating a snapshot with the extended and frozen global object could 
Just an idea, don't know how feasible that is.

** Qt Developer Conference: http://qtconference.kdab.com/ **

Thomas McGuire | thomas.mcguire at kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel. Germany +49-30-521325470, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3637 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20121012/0cf54256/attachment.bin>

More information about the Development mailing list