Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26292] Windows: Switching to JsRT (Chakra) for better performance

GitHub Issuen/a
TypeEpic
PriorityHigh
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 7.4.0
Fix Version/sn/a
ComponentsWindows
Labelsn/a
ReporterKota Iguchi
AssigneeKota Iguchi
Created2018-08-13T00:59:21.000+0000
Updated2019-01-08T01:03:12.000+0000

Description

Peformance has been the issue on Windows for a long time. From what I observed, some basic JavaScript operations (like calling constructor, accessing properties and functions) against Titanium proxy objects are simply slow. For instance, creating 200 proxy objects on Windows (Titanium 7.4.0.GA) takes about 2 seconds on Windows locally for me.
var win = Ti.UI.createWindow({ backgroundColor: 'green' });

win.addEventListener('open', function() {
    var start = +new Date();
    for (var i = 0; i < 200; i++) {
        win.add(Ti.UI.createView({
            width: 50, height: 50, left: i * 10, top: i * 10
        }));
    }
    // setTimeout() effectively push tasks on UI thread.
    // This can be useful when you need to see actual UI response time.
    setTimeout(function() {
        alert((+new Date() - start) + ' seconds elapsed');
    }, 0)
});
win.open(); 
We have been improving performance overall and have archived huge improvements like TIMOB-23637 but yet we can't keep up with other platforms regarding performance now, I am guessing that huge difference between other platforms (especially between iOS) is that the unavailability of JIT (Just In Time) compiler on our JavaScript engine. On Windows, JIT is not enabled because it is not available yet. It is huge disadvantage regarding performance. So this is quite fundamental issue. In order to improve performance, we might want to consider developing JavaScriptCore JIT for Windows, or try switching to Chakra, a JavaScript engine which Microsoft developed, which should have JIT enabled and should provide much better performance unlike our custom JavaScriptCore port. Again this requires big-and-fundamental changes regarding our Titanium (AKA TitaniumKit and HAL) framework overall technically, and I don't think we can archive huge peformance improvements without this.

Comments

  1. Kota Iguchi 2018-08-14

    According to ChakraCore [JavaScript Runtime (JSRT) reference](https://github.com/Microsoft/ChakraCore/wiki/JavaScript-Runtime-%28JSRT%29-Reference), it is highly likely feasible to implement part of HAL APIs such as JSValue because ChakraCore has similar APIs like JSValueRef. ChakraCore also provides a way to define native callback functions by using [JsNativeFunction](https://github.com/Microsoft/ChakraCore/wiki/JsNativeFunction) that gives us a way to simulate HAL::JSExport API. One thing I noticed that's missing is the ability to define property callbacks. This is critical because HAL API needs it. So we might want to consider fundamental changes in HAL if we use ChakraCore, like generating getter/setter for Titanium properties by using Object.defineProperties at startup. Luckily ChakraCore provides a way to serialize scripts using [JsSerializeScript](https://github.com/Microsoft/ChakraCore/wiki/JavaScript-Runtime-%28JSRT%29-Overview#script-serialization-with-lazy-source-loading), that may be very useful to pre-parse and lazy-load Titanium classes at runtime. The other downside is that ChakraCore doesn't support iOS and Android. It may be critical because originally HAL and TitaniumKit was aiming to be cross-platform.

JSON Source