Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28412] iOS: Optimize JS Promise creation on iOS 12

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2021-06-17T11:53:30.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.0.1
ComponentsiOS
Labelsasync, iOS, performance, promise
ReporterJoshua Quick
AssigneeJoshua Quick
Created2021-04-02T01:43:38.000+0000
Updated2021-06-17T11:53:30.000+0000

Description

*Summary:* On iOS 12 and older versions, there is no native API to create a JavaScript Promise. So, we create promises via a JS eval() as shown below... https://github.com/appcelerator/titanium_mobile/blob/master/iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollPromise.m#L35-L49 *To-Do:* We should optimize this so that we don't do an eval() every time a promise needs to be created. Simplest solution is to only create the JS promise handling function once and re-use it. *Note:* Apple documents that evaluateScript() will add function/variable definitions permanently to the global context. https://developer.apple.com/documentation/javascriptcore/jscontext/1451350-evaluatescript This means we should use a unique prefixing convention to avoid collision. Also, every time we define our JS executor() and createPromise() functions, theoretically we're slowly bloating the JS global context with these re-definitions. This may be a slow memory leak.

Comments

  1. Joshua Quick 2021-04-02

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12684
  2. Ewan Harris 2021-06-17

    master and backport merged

JSON Source