[Development] QML, v8 and freezing the global object

Jedrzej Nowacki jedrzej.nowacki at digia.com
Fri Oct 12 10:17:20 CEST 2012


On Thursday 11. October 2012 16.04.04 Thomas McGuire wrote:
> Hi,
> 
> the QML engine "freezes" the global JS object. This is apparently(?) to
> prevent accidental writes to the global object. For those who don't know,
> the global object in JS provides objects and properties available in
> global scope, such as "console" (for console.log) or "qsTr".
> 
> Now, it turned out that freezing the global object takes a lot of time with
> v8 on BB10 devices. Even in release mode, just the call to freeze the
> global object makes the startup time 100ms longer.
> 
> v8 seems to have an implmentation of freezing that is suboptimal, see for
> example the benchmark at http://jsperf.com/performance-frozen-object. Note
> this benchmark is for iterating over properties of frozen objects, not
> freezing an object, though likely freezing an object would get similar
> benchmark results.
> 
> Could we maybe simple get rid of object freezing, and not freeze the global
> object?
> What would the consequences of that be, anything bad? I am the opinion that
> if the user wants to override the "console" object, let him. Maybe there
> were other reasons for freezing the global object though?
> 
> Regards,
> Thomas

Hi,

  Freezing global object was a language design decision. The problem was that 
in QML it would be much easier accidentally add a property to the global 
object then in JS. Such mistakes would be quite difficult to debug in QML. As a 
side effect there is a few optimizations in declarative engine that assume 
frozen global object. As far I remember they speedup property lookup.

  Algorithm for freezing an object, was never benchmarked. Probably you can 
optimize it. You my also try to enable v8 snapshots, if it is not enabled on 
your configuration. According to our test it may increase qml boot time about 
5x. I do not know if it is already done but, maybe you can create a snapshot 
with frozen global object, that could solve your problem.

Good luck :-)

  Jędrek



More information about the Development mailing list