Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25768] Use rollup to avoid circular references with ES6 imports in JavascriptCore

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Do
Resolution Date2020-06-30T14:40:42.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS, Windows
Labelsn/a
ReporterGary Mathews
AssigneeChristopher Williams
Created2018-02-09T22:55:49.000+0000
Updated2020-06-30T14:40:42.000+0000

Description

- JavascriptCore does not have full ES6 module support, circular references with import will cause a stack overflow *TEST CASE*
// TODO

Comments

  1. Gary Mathews 2018-02-12

    master: https://github.com/appcelerator/node-titanium-sdk/pull/24
  2. Christopher Williams 2018-02-26

    Note that right now if users use ES6 they have to have transpilation turned on, which will currently convert imports to require calls under the hood (at least from my experience) So I'm not sure if we're yet at the point where this is a priority...
  3. Christopher Williams 2018-05-23

    Pushing to 7.4.0 for now, babel will transpile imports to require under the hood for now. We need to figure out how to hook rollup into our build lifecycle to support this properly as it needs to run first and will only work when the app has *only* import/exports.
  4. Joshua Quick 2018-06-22

    After talking to [~cbarber], we may want to use "rollup" for performance reasons as well. Particularly for large alloy apps which may have a lot of generated JS files to require-in. I did some benchmarks for how long a require() call takes using the below... *app.js*
       var startTime = new Date();
       require('Test');
       Ti.API.info('@@@ require() duration: ' + (new Date() - startTime));
       
    *Test.js*
       // I'm an empty file.
       
    Below are my benchmarks:
       iOS 10 Simulator:     3 ms
       Android 4.1 Emulator: 1 ms
       Amazon Fire HD 8:     3 ms
       Galaxy Nexus:         5 ms
       Pixel XL:             2 ms
       
    The above numbers are not huge, but it can add up quickly for apps that have a lot of JS files. I'm sure we can do other things to reduce the require() overhead internally (except for JS decryption; we have to keep that), but I think it's worth benchmarking the performance gain with "rollup" to see if it helps.
  5. Hans Knöchel 2018-06-22

    For iOS, we are caching require-statements already, not sue how Android works there.
  6. Joshua Quick 2018-06-22

    The above benchmarks are for the initial require when doing a cold start of the app. Android is definitely caching previously required files as well, but there is extra overhead on the Android side where each JS file gets their own copy of our core Titanium libraries which isn't great. They're not being loaded into the global namespace for some reason. (That's a whole different discussion.) The only thing I don't like about "rollup" of all the scripts is if the code count is large, then the startup time is going to be worse versus lazy loading. "rollup" might be a good idea for our core JS code and generated alloy code from a performance perspective, but it doesn't solve the recursive import issue Gary is trying to resolve. Hmm...
  7. Christopher Williams 2018-06-26

    Some notes: - I believe Gary was trying to address a circular dependency issue with raw import calls. As mentioned above, we don't really support using import unless you transpile, and right now Babel transpiles import to actually be require calls. This situation would only really occur when using import/export syntax and *not* turning on transpilation. (Which given that we're likely to move to transpile by default would become even less likely). - I do think that rollup is a possible packaging option we could provide in the future to help shrink app size, reduce performance issues around a large codebase, etc. The complicating factor here is that we don't really have all the pieces set up to enable it. The codebase, including any JS code in the core/modules it needs, *has* to use import/export instead of require to get the benefits. And it would have to run on the codebase *before* transpilation (since transpiling transforms imports). We haven't really addressed how to handle that in the build hook lifecycle/pipeline, and we don't generate import/export style code in hyperloop/Alloy to make use of this.
  8. Hans Knöchel 2018-11-02

    We are currently running into this on iOS when importing different managers (api, login, request) into each other. A timely workaround or fix would be appreciated!

JSON Source