{"id":581,"date":"2018-07-27T09:50:22","date_gmt":"2018-07-27T09:50:22","guid":{"rendered":"http:\/\/fluentreports.com\/blog\/?p=581"},"modified":"2019-02-13T04:55:29","modified_gmt":"2019-02-13T04:55:29","slug":"nativescript-application-wide-android-runtime-settings","status":"publish","type":"post","link":"http:\/\/fluentreports.com\/blog\/?p=581","title":{"rendered":"NativeScript application wide runtime settings (updated 5.2)"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignright is-resized\"><a href=\"http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2018\/07\/ns-cube.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2018\/07\/ns-cube.png\" alt=\"NativeScript Switch\" class=\"wp-image-587\" width=\"378\" height=\"291\" srcset=\"http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2018\/07\/ns-cube.png 800w, http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2018\/07\/ns-cube-300x231.png 300w, http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2018\/07\/ns-cube-768x592.png 768w, http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2018\/07\/ns-cube-624x481.png 624w\" sizes=\"auto, (max-width: 378px) 100vw, 378px\" \/><\/a><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">On thing most people are probably not aware of is that the Android runtimes has a large number of knobs and switches to customize certain behavior of the engine.&nbsp;&nbsp; I will try and list out all the current switches and knobs that you can use.&nbsp;&nbsp; iOS now has one switch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First of all the settings go into the <strong>\/app\/package.json<\/strong>&nbsp;&nbsp; If you open up the default package json you probably will see:<\/p>\n\n\n\n<pre>{&nbsp;&nbsp; \n&nbsp;&nbsp;&nbsp;&nbsp;&quot;android&quot;: {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;v8Flags&quot;: &quot;--expose_gc&quot;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp; },&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp; &quot;main&quot;: &quot;app.js&quot;,\n&nbsp;&nbsp; &quot;name&quot;: &quot;tns-template-hello-world&quot;,\n&nbsp;&nbsp; &quot;version&quot;: &quot;5.2.0&quot;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That \"<strong>android<\/strong>\" key is where everything goes for Android specific settings.&nbsp;&nbsp; The default setting that comes in the files is <code>&quot;v8Flags&quot;: &quot;--expose_gc&quot;<\/code> this one is rather critical in that this enabled the runtime to call gc from JavaScript.&nbsp;&nbsp; Now, there is quite a few v8Flags you can use; most the time they aren't needed but if you need to tune the v8 engine; you can add more flags into this string.&nbsp; I even list a few in this <a href=\"http:\/\/fluentreports.com\/blog\/?p=284\">post<\/a>.&nbsp;&nbsp; Let me warn you again; <strong>DO NOT remove the \"--expose_gc\".&nbsp;<\/strong>&nbsp; You will cause your app to crash when something attempts to call the GC from code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As of version 5.2;  there is a \"<strong>ios<\/strong>\" key called \"<strong>jscFlags<\/strong>\" option that is now available.   My recommendation while building\/testing your app is to add the key <code>&quot;ios&quot;: { &quot;jscFlags&quot;:&quot;--validateOptions=1&quot; }<\/code> The jscFlags has items that can be used to tweak the JavaScript core engine.  You can find more flags <a href=\"https:\/\/github.com\/NativeScript\/webkit\/blob\/ios\/Source\/JavaScriptCore\/runtime\/Options.h#L115\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ok, so here is the complete list of settings you can change in the Android section:<\/p>\n\n\n\n<table class=\"wp-block-table has-fixed-layout nowrap is-style-regular\"><tbody><tr><td><strong>Setting<\/strong><\/td><td><strong>Default<\/strong><\/td><td><strong>Min&nbsp;Version<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>gcThrottleTime<\/td><td>0<\/td><td>3.x<\/td><td>Allows you to throttle <br>how frequently JS GC <br>triggers native GC<br>See:<br><a href=\"https:\/\/docs.nativescript.org\/core-concepts\/android-runtime\/advanced-topics\/memory-management\">Memory Management<\/a><\/td><\/tr><tr><td>memoryCheckInterval<\/td><td>0<\/td><td>3.x<\/td><td>How frequently to check<br>memory usage<br>See:<br><a href=\"https:\/\/docs.nativescript.org\/core-concepts\/android-runtime\/advanced-topics\/memory-management\">Memory Management<\/a><\/td><\/tr><tr><td>freeMemoryRatio<\/td><td>0.0<\/td><td>3.x<\/td><td>Ration of memory before a GC is ran (works with <br>memoryCheckInterval)<br>See: <br><a href=\"https:\/\/docs.nativescript.org\/core-concepts\/android-runtime\/advanced-topics\/memory-management\">Memory Management<\/a><\/td><\/tr><tr><td>markingMode<\/td><td>full<\/td><td>3.x<\/td><td>Switches which type of GC engine to use.\u00a0 \"none\" will enable a different engine which doesn't do <br>marking.\u00a0 Typically faster <br>for Angular apps<\/td><\/tr><tr><td>handleTimeZoneChanges<\/td><td>false<\/td><td>4.1<\/td><td><strong>True<\/strong> will enable the <br>ability for a time zone <br>change in the settings to<br>effect the NS app.<\/td><\/tr><tr><td>maxLogcatObjectSize<\/td><td>1024<\/td><td>4.0<\/td><td>How many lines of text a<br>console output will log.<\/td><\/tr><tr><td>forceLog<\/td><td>false<\/td><td>4.0<\/td><td><strong>True<\/strong> will enable logging <br>in release mode<\/td><\/tr><tr><td>suppressCallJSMethodException<\/td><td>false<\/td><td>5.1<\/td><td><strong>True<\/strong> will suppress the<br>boolean type conversion error from null that could randomly occur and crash the application.<\/td><\/tr><tr><td>codeCache<\/td><td>false<\/td><td>2.x<\/td><td><strong>True<\/strong> - Enables code<br>caching in the v8 engine.<\/td><\/tr><tr><td>v8Flags<\/td><td>--expose_gc<\/td><td>1.x<\/td><td>Tunes the v8 engine<\/td><\/tr><tr><td>heapSnapshotBlob<\/td><td>\"\"<\/td><td>2.x<\/td><td>(Believe to be unused <br>now)<\/td><\/tr><tr><td>heapSnapshotScript<\/td><td>\"\"<\/td><td>2.x<\/td><td>(Believe to be unused <br>now)<\/td><\/tr><tr><td>snapshot.blob<\/td><td>\"\"<\/td><td>2.x<\/td><td>(Believe to be unused <br>now)<\/td><\/tr><tr><td>profilerOutputDirKey<\/td><td>\"\"<\/td><td>2.x<\/td><td>(Believe to be unused <br>now)<\/td><\/tr><tr><td>profiling<\/td><td>\"\"<\/td><td>2.x<\/td><td>(Believe to be unused <br>now)<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>IOS Level Flags:<\/strong>\n<\/p>\n\n\n\n<table class=\"wp-block-table has-fixed-layout\"><tbody><tr><td><strong>Setting<\/strong><\/td><td><strong>Default<\/strong><\/td><td><strong>Min Version<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>gcThrottleTime<\/td><td>0<\/td><td>5.2<\/td><td>Allows you to throttle <br>how frequently JS GC <br>triggers native GC<br>See: <a href=\"https:\/\/docs.nativescript.org\/core-concepts\/ios-runtime\/custom-flags\">Custom Flags<\/a><\/td><\/tr><tr><td>memoryCheckInterval<\/td><td>0<\/td><td>5.2<\/td><td>How frequently to check memory usage<br>See: <a href=\"https:\/\/docs.nativescript.org\/core-concepts\/ios-runtime\/custom-flags\">Custom Flags<\/a><\/td><\/tr><tr><td>freeMemoryRatio<\/td><td>0.0<\/td><td>5.2<\/td><td>Ration of memory before a GC is ran (works with<br>memoryCheckInterval)<br>See: <a href=\"https:\/\/docs.nativescript.org\/core-concepts\/ios-runtime\/custom-flags\">Custom Flags<\/a><\/td><\/tr><tr><td>jscFlags<\/td><td>\"\"<\/td><td>5.2<\/td><td>Tunes the JavaScriptCore engine.  <a href=\"https:\/\/github.com\/NativeScript\/webkit\/blob\/ios\/Source\/JavaScriptCore\/runtime\/Options.h#L115\">Valid Flags<\/a><\/td><\/tr><\/tbody><\/table>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Top Level Global Flags:<\/strong><\/p>\n\n\n\n<table class=\"wp-block-table has-fixed-layout\"><tbody><tr><td><strong>Setting<\/strong><\/td><td><strong>Default<\/strong><\/td><td><strong>Min Version<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>discardUncaughtJsExceptions<\/td><td>false<\/td><td>4.2<\/td><td><strong>True<\/strong> - will disable<br>crashing on JS errors, will<br>log any issues to console.<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Recommended changes:<\/strong><br><code>discardUncaughtJsExceptions: &quot;true&quot;<\/code> - This will keep the app from crashing on certain types of errors; this should be enabled for release mode! Some developers might find it more productive to have this enabled while coding to eliminate application crashes. Please note you MUST pay attention to the console if you enable this during development; because most JS errors that would crash out; will now be just logged to the console.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>suppressCallJSMethodExceptions: &quot;true&quot;<\/code> - This will keep the app from crashing on the boolean conversion issue that can occasionally occur.&nbsp; This is not to say the app might have some other issue later; but this will eliminate a stupid (imho) crash reason.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>markingMode: &quot;none&quot;<\/code> - This will enable the experimental GC engine, this will help incredibly with Angular based apps. Please note it \"might\" cause more crashing errors if a plugin forgot to hold a reference to something it needed later. However with the above <em>discardUncaughtJsExceptions<\/em> enabled; those errors won't crash the app.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Late Breaking news; in 4.2 they actually moved \"<strong>discardUncaughtJsExceptions<\/strong>\" to the top level of the package; the reason why is because shortly after they added the support to Android; the support was added to iOS.&nbsp; So now this flag controls both iOS and Android, so it no longer belongs just in the \"<strong>android<\/strong>\" block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So in your package json would look like this if you used my recommended settings:<\/p>\n\n\n\n<pre>{\n&nbsp;&nbsp; &quot;android&quot;: {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;v8Flags&quot;: &quot;--expose_gc&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;markingMode&quot;: &quot;none&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;suppressCallKSMethodExceptions&quot;: &quot;true&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;ios&quot;: {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;jscFlags&quot;: &quot;--validateOptions=1&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;discardUncaughtJsExceptions&quot;: &quot;true&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;main&quot;: &quot;app.js&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;name&quot;: &quot;tns-template-hello-world&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;version&quot;: &quot;5.2.0&quot;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>On thing most people are probably not aware of is that the Android runtimes has a large number of knobs and switches to customize certain behavior of the engine.&nbsp;&nbsp; I will try and list out all the current switches and knobs that you can use.&nbsp;&nbsp; iOS now has one switch. First of all the settings&hellip; <a class=\"more-link\" href=\"http:\/\/fluentreports.com\/blog\/?p=581\">Continue reading <span class=\"screen-reader-text\">NativeScript application wide runtime settings (updated 5.2)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[15,7,39],"tags":[17,16,117,116],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-nativescript","category-performance","category-tips","tag-android","tag-nativescript","tag-settings","tag-v8flags","entry"],"_links":{"self":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=581"}],"version-history":[{"count":19,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":684,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/581\/revisions\/684"}],"wp:attachment":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}