Why using nth in clojurescript increases my code by 74026%

I compared the generated javascript received by various calls to clojurescript, and it feels like switching to land mines. Some of them generate extremely readable (even in extended advanced mode) javascript, and some decide that this method call will require all possible methods to be executed in clojure.

nth vs aget is a very good example of this. Both of these code snippets print the number 5, but this requires 77 bytes and the other 57 kilobytes. This is an increase of 74,026%

57 KiloBytes - nth

(ns fooModule) (let [log js/console.log x (array 5)] (log (nth x 0))) 

77 bytes - aget

 (ns fooModule) (let [log js/console.log x (array 5)] (log (aget x 0))) 

The code created by aget is very readable. (formatting is done manually)

 ;(function(){ var a=console.log, b=[5]; aa ? aa(b[0]) : a.call( null, b[0] ); })(); 

generated nth code in gist https://gist.github.com/trashhalo/7781298 \

clojurescript 0.0-2014

+7
javascript clojure clojurescript
source share
1 answer

In this case, It is due to the elimination of dead code that interacts with ClojureScrip sequences. Your example just uses only one thing that uses sequences, nth and nothing else. Therefore, when in the first example, the seq library is discarded, and in the second, not. Do not generalize this growth rate , there is only about such a sum of ClojureScript, therefore, as soon as you use any code that includes it, you will figuratively attack all mines.

+11
source share

All Articles