標題: 針對 JavaScript ⾼階函數的最佳化
Higher-Order Function Optimization in JavaScript
作者: 陳枝懋
游逸平
Chen, Chih-Mao
You,Yi-Ping
資訊科學與工程研究所
關鍵字: JavaScript;函數式程式設計;最佳化;JavaScript;Functional Programming;Optimization
公開日期: 2017
摘要: JavaScript是開發Web應用程式的標準語言,並支援多種編程範形,例如指令式、函數式、物件導向程式設計等。其中函數式程式設計是一種視電腦程式為數學函數求值的方式,讓程式設計師能以更高階的方式撰寫程式。函數式程式設計經常使用高階函數以抽象化程式,但在JavaScript中使用高階函數可能造成效能上的影響。我們提出了一個JavaScript的編譯器將高階函數轉換為其對應的低階迴圈,使程式設計師可以使用高階函數撰寫程式也不失去程式的性能。我們轉換JavaScript至中介語言Thorin,並在其中找出可消除的高階函數,再使用Relooper演算法將其轉換回JavaScript。我們的實驗顯示它可以消除高階函數抽象化所造成的效能影響,而最佳化的程式和人為使用低階迴圈的程式效能相近。
JavaScript is the de facto programming language for developing interactive Web applications. It supports multiple programming paradigms such as imperative, prototype-based object-oriented, and functional programming. Function programming, a style of treating computation as evaluation of mathematical functions, enables programmers to express algorithms in a higher-level form, thereby shielding programmers from dealing with low-level details and resulting in more readable and concise code. One of the building blocks of functional programming is the use of higher-order functions, which take one or more functions as arguments or return a function as their result. However, higher-order functions in JavaScript presents a serious performance cost when they are not identified and optimized in most JavaScript engines. In this thesis, we present a source-to-source compiler that attempts to rewrite higher-order functions into their corresponding loop forms, enabling programmers to use higher-order functions without sacrificing performance. We translate the JavaScript source to a functional, CPS-based IR based on Thorin, identify and eliminate higher-order functions, and then translate back to JavaScript using an adapted Relooper algorithm. Our experimental result shows that it is capable of eliminating the overhead introduced by HOF abstractions, and the performance of the optmized program is on par of hand-written ones using primitive control flow structures.
URI: http://etd.lib.nctu.edu.tw/cdrfb3/record/nctu/#GT070356162
http://hdl.handle.net/11536/140423
顯示於類別:畢業論文