神刀安全网

More cljsfiddle Upgrades

31 Mar 2016

New Hosting

Cljsfiddle used to be served off of aws S3 because that was quickest way to set it up (using the fabulous s3cmd (install via brew install s3cmd (or probably from your favorite package manager (thanks paredit )))).

Such Tabular:

New Host (nginx) Old Host (s3)
8.5 38.7
10.5 72
7.8 45.7
7.2 49.2
6.9 19.2
Mean: 8.18 Mean: 44.96
Total speedup: over 5x faster!

More cljsfiddle Upgrades

And so, we see the value of compressing content for highly repetitive files such as those produced by the ClojureScript compiler.

In the past, I hadn’t noticed compression making much of a difference for cljs projects. I have a hunch that’s because unlike 90%+ of cljs projects, cljsfiddle cannot use advanced compilation mode because it needs to load the cljs-in-cljs bootstrapped clojurescript compiler.

Compression aside

Everyone knows zipping a file tends to make it smaller. Compression works by looking at a sequence (let’s say of characters), and assigning long, frequently repetitive sequences in that string to shorter keys. The longer and more repetitive a substring is, the shorter its key should be. In this way a compression algorithm builds a legend from short symbol -> long symbol. Having one large file makes compression easier because instead of many small (and in the case of code, certainly redundant) legends, we can have a larger legend that only needs to do its work once.

example1: AAABAAABAAABAAAB

vs:

example2: AAABAAAB and AAABAAAB

We build the legend 1=AAAB . In our imaginary naive compression algorithm, we include the legend first, then a | , then the data itself. So:

compress(example1) => 1=AAAB|1111 compress(example2) => 1=AAAB|11 and 1=AAAB|11

The length of compressed example1 is: 11. The length of compressed example two is: 18!! So we can see how having a larger, concatenated file helps with compression.

The clojurescript compiler’s :whitespace mode allows us to do exactly that.

Whitespace optimization!

Table 1: Compress bigger files!
None Optimization Whitespace Optimization
8.5 4.1 (!)
10.5 4.2
7.8 7.5
7.2 7.3
6.9 7.4
8.18 6.1
Total speedup: over 7x faster than s3!

So, even though we don’t download the app.js file in parallel, we still save bandwidth and decrease load times.

Thanks to:

Nicolás Berger

For contributions such as updating cljs to use :whitespace mode, and changes to the way we call bootstrapped compiler, and more!

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » More cljsfiddle Upgrades

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮