{"id":313,"date":"2016-05-22T03:21:09","date_gmt":"2016-05-22T03:21:09","guid":{"rendered":"http:\/\/fluentreports.com\/blog\/?p=313"},"modified":"2016-05-22T03:34:08","modified_gmt":"2016-05-22T03:34:08","slug":"nativescript-typescript-speedmemory-usage","status":"publish","type":"post","link":"http:\/\/fluentreports.com\/blog\/?p=313","title":{"rendered":"NativeScript: TypeScript Speed\/Memory usage"},"content":{"rendered":"<p>For those who may have seen some post of mine on Slack about TypeScript being not a performant as JavaScript; I have finally done the real benchmarks and spent the time totally de-typescriptifing the NativeScript 2.00 runtimes.\u00a0 And here is my startling results....<\/p>\n<figure id=\"attachment_314\" aria-describedby=\"caption-attachment-314\" style=\"width: 429px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2016\/05\/everythingyouknowiswrong.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-314\" src=\"http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2016\/05\/everythingyouknowiswrong.jpg\" alt=\"everythingyouknowiswrong\" width=\"429\" height=\"322\" srcset=\"http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2016\/05\/everythingyouknowiswrong.jpg 800w, http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2016\/05\/everythingyouknowiswrong-300x225.jpg 300w, http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2016\/05\/everythingyouknowiswrong-768x576.jpg 768w, http:\/\/fluentreports.com\/blog\/wp-content\/uploads\/2016\/05\/everythingyouknowiswrong-624x468.jpg 624w\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" \/><\/a><figcaption id=\"caption-attachment-314\" class=\"wp-caption-text\">(c) 2010, Jan-Willem Reusink - https:\/\/www.flickr.com\/photos\/jimmybenson<\/figcaption><\/figure>\n<p>Oh, wait; that is not right -- I was the one wrong.\u00a0 \ud83d\ude09<\/p>\n<p>The actual real numbers do not bear out what I had believed based on some TypeScript tests that I had done in Node a while back.\u00a0 I am still not sure why my initial tests in Node behaved differently; but after spending a couple days building the tests, using a large JS application and a totally de-typescriptified the NativeScript runtime, I can say without a doubt in my mind that TS add little to no meaningful hit to the runtimes.\u00a0 On iOS I actually didn't see a memory difference at all, the GC seems to collect the memory so quickly, that it wasn't even showing up.\u00a0\u00a0\u00a0 On android it takes about 40-60 more megabytes of memory for everything; however after the first GC, all the memory is reclaimed.\u00a0\u00a0\u00a0\u00a0 So yes, you do end up with a small amount wasted memory and GC pressure added.\u00a0 However, with it ALL being reclaimed at the first GC; 40mb temporarily wasted really is a drop in the bucket for what TS does offer you.<\/p>\n<p>The other thing that I was surprised by was that the TS runtimes actually started up faster than the pure JS versions.\u00a0 Now that I had to reason through why TS code was starting faster than raw JS; it makes a lot of sense -- The reason why is because most classes are lazy instantiated.\u00a0 So the amount of JS code actually compiled and ran by the v8\/JSC engines are a lot smaller in TS compiled code because the majority of the code is inside the function that wraps each class.\u00a0\u00a0 So if a class isn't needed yet during startup (but is loaded via the require statements) then the time it spends running it is minuscule compared to a runtime that actually builds all the classes while it is loading each one.\u00a0 So, even though the difference was in literally milliseconds, it still was measurable.\u00a0 Eventually when you do have that class instanciated; you will have more time used their; but since each class being created later is literally measured in NanoSeconds, the hit later actually \"feels\" faster to the user since time to first pixel ended up being faster using TypeScript code...<\/p>\n<p>Actual numbers (best of):<\/p>\n<p>Startup time TS: <strong>393,675,213<\/strong> (NanoSeconds)<br \/>\nStartup time JS:\u00a0 <strong>399,058,778<\/strong> (NanoSeconds)<\/p>\n<p>Memory Usage TS: <strong>7,544,460<\/strong> (Bytes)<br \/>\nMemory Usage JS: <strong>7,488,292<\/strong> (Bytes)<\/p>\n<p>Memory after GC TS: <strong>4,979,548<\/strong> (Bytes)<br \/>\nMemory after GC JS: <strong>4,993,268<\/strong> (Bytes)<\/p>\n<p>Please note the reason why GC JS is actually bigger than GC'd TS is more (all) classes have been defined, created and are in memory as real objects vs the raw un-instanciated source code in TS if they haven't been used yet.<\/p>\n<p>So, guess what I am going to be using more of....\u00a0 \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For those who may have seen some post of mine on Slack about TypeScript being not a performant as JavaScript; I have finally done the real benchmarks and spent the time totally de-typescriptifing the NativeScript 2.00 runtimes.\u00a0 And here is my startling results.... Oh, wait; that is not right -- I was the one wrong.\u00a0&hellip; <a class=\"more-link\" href=\"http:\/\/fluentreports.com\/blog\/?p=313\">Continue reading <span class=\"screen-reader-text\">NativeScript: TypeScript Speed\/Memory usage<\/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":[1],"tags":[],"class_list":["post-313","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/313","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=313"}],"version-history":[{"count":3,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/313\/revisions"}],"predecessor-version":[{"id":317,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/313\/revisions\/317"}],"wp:attachment":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}