HashBang icon indicating copy to clipboard operation
HashBang copied to clipboard

Slow JavaScript Compilation in Release Build

Open cata opened this issue 10 years ago • 4 comments

Hi Zack,

95% of the compilation time is spent in YuiCompressor.Net. The YuiCompressor.Net implementation uses ArrayLists in way which makes it extremely inefficient when the JavaScript to be compressed contains a large number of short identifiers.

Compilation times on my system and resulting file sizes (the entire HashBang file - HTML + CSS + JavaScript) (release build, 023f8a4):

  1. Funscript( compression: on) ~2s, 0.92 MB
  2. Funscript( compression: off) ~2 s, 1.27 MB
  3. Funscript( compression: on) + YuiCompressor.Net: ~38s, 0.72 MB
  4. Funscript( compression: off) + YuiCompressor.Net: ~7s, 1.0 MB

While it is true that option3 (the one currently in use in release mode) achieves the best compression, I am thinking the performance cost is unacceptable - especially in the current scenario, in which the compilation is performed at site start-up.

As an aside, note that utilizing the YuiCompressor to compress uncompressed FunScript-generated JavaScript is both slower and less efficient than using FunScript compression exclusively.

I think that modifying the code to only use the compression achieved by Funscript alone is acceptable at this stage (I vote for modifying HashBang to use option 1, until the performance of 3 can be addressed).

Moving forward, I see two long-term solutions:

  1. Optimize YuiCompressor.Net - speaking of which: YuiCompressor.Net fails as of 5385839 (works for 023f8a4 - and I have yet to check at which point it broke).
  2. Improve Funscript's native JavaScript compression

Let me know how you'd like to proceed.

Catalin

cata avatar Nov 10 '14 03:11 cata

Wow!

Thanks for these statistics Catalin. I had assumed it was mostly FunScript taking the time.

It seems quite bizarre that FunScript and Yui compression both turned on results in such a drastically long compilation time in comparison to either of them turned on individually.

We may be able to make the FunScript output more Google Closure friendly and use that instead. There is also a lot of room for improvement in the quality and size of the FunScript output.

I agree with your idea to turn off Yui for now and then maybe we should focus on the FunScript output in the long term.

ZachBray avatar Nov 10 '14 22:11 ZachBray

BTW master is quite a bit behind my feature/chat-sample branch at the moment.

ZachBray avatar Nov 10 '14 22:11 ZachBray

I'll turn Yui off in the branch now.

ZachBray avatar Nov 10 '14 22:11 ZachBray

Regarding JavaScript compression: Cool, sounds like a plan. Good to know where to focus future optimization efforts - I like the idea of improving FunScript's JavaScript generation, as it keeps usage simple and removes dependencies.

Regarding the master branch: Yes, I've noticed - currently on the feature/chat-sample branch :-)

cata avatar Nov 10 '14 22:11 cata