[ALOY-1263] Compiler should force "strict mode" to increase (Android) performance

GitHub Issuen/a
Resolution Date2017-05-03T07:38:09.000+0000
Affected Version/sn/a
Fix Version/sn/a
ReporterFokke Zandbergen
AssigneeFeon Sua Xin Miao


Looking for optimisations of https://github.com/appcelerator-developer-relations/Mobile-App-Performance I saw that enable strict mode meant a 20x performance increase on Android and a significant increase on iOS as well. Unfortunately, because "use strict"; needs to be the first line of the file or function scope and Alloy wraps the original controller code, a developer cannot (simply) enable strict mode. The workaround is to wrap inline controller code in a self-executing function and add "use strict"; as the first line for this and every other function. https://community.appcelerator.com/topic/391/how-to-enable-strict-mode-in-alloy

Phase 1: Always add strict

We should probably promote strict mode in our docs, but with Alloy we could even force it. Simply adding "use strict"; to all compiled files will only mean a slight decrease of performance if the code is not really strict but a huge increase if it is, as this [StackOverflow user found](http://stackoverflow.com/questions/23997267/using-node-why-is-code-so-much-faster-with-use-strict).

Phase 2: Correct code to be strict

I'm not sure if UglifyJS maybe already does this, but there's several packages out there that can automatically correct strict lint errors and thus make the code strict for the user (or warn him if it's not).


  1. Ryan Gartin 2016-07-17 Any progress on this?
  2. Francois van Lille 2016-09-05 I second the motion to get some movement on this, as it sounds so simple a gap to bridge in theory and no-one has claimed anything to the contrary. Given the widely accepted benefits of running strict mode code, surely we could bump this up the list of things to do? If you're working in an editor that supports JS linting (such as Atom, which I believe more and more people are doing), you're bombarded with warnings about unnecessary 'use strict' directives, which I for one would not mind seeing the back of... If a well-placed rant doesn't get the job done, maybe I should pull my finger, fix it myself and submit a pull request, eh? Although a soap-box is so much easier to come by...
  3. Anders Dahl Pape 2016-09-07 If Francois hasn't pulled his finger ;) I would also like to see this happen! If the performance gain is that massive it's an easy win with many Titanium developers.
  4. Creative 2016-12-15 bump Someone raise this priority please.
  5. John Dalsgaard 2016-12-15 Would be nice if this was implemented.... I have started looking into doing this manually - but would be so much nicer to have it done automatically. If backwards compatibility is an issue then perhaps make it possible use by setting some configuration somewhere on the project... (tiapp.xml perhaps?)
  6. Hans Knöchel 2017-04-16 Hey [~fmiao], can you take a look and scope this out?
  7. Feon Sua Xin Miao 2017-04-18 PR: https://github.com/appcelerator/alloy/pull/823
  8. Hans Knöchel 2017-05-03 We decided to not implement this change at all, because most recent benchmarking tests related to the above PR did not result in an improved Alloy performance. If there are other thoughts on this, please test the PR and let us now, but for now we will go with the current Alloy implementation and expect huge speed improvements in Alloy v2 which will begin planning this week. Thanks!
  9. Eric Merriman 2018-03-07 Closing as invalid. If this is incorrect, please reopen.

JSON Source