[TIMOB-28412] iOS: Optimize JS Promise creation on iOS 12
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2021-06-17T11:53:30.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 10.0.1 |
Components | iOS |
Labels | async, iOS, performance, promise |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2021-04-02T01:43:38.000+0000 |
Updated | 2021-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.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/12684
master and backport merged