| Nowadays, the execution speed of scripting languages has become amain factor that restricts the development of web applications. SinceJavaScript is the most widely used programming language on the Web, itsperformance improvement is very important for the development ofcompute-intensive web applications. Currently, there are many researcheson the optimization of JavaScript engines, but still no perfect solutions tothe parallelization and performance improvement of the language itself.Aiming at this emerging field, this article did some researches andexplorations from different perspectives, which are of important practicalsignificance to the performance of web browsers.This article firstly described the JavaScript language and parallelprogramming, and introduced Chromium’s multi-threaded architecturewith sandbox mechanism. Then, by adding a new module to the WebKitengine, this article designed a parallel JavaScript extension based onWebKit and implemented it in the Chromium browser. This extensionparses and translates the kernel functions in JavaScript, then callsOpenCL runtime library for parallel computing, and binds these modulesto V8via an IDL module. Meanwhile, this article analyzed the securityand compatibility requirements of web languages and optimized thewhole process of the extension. After the optimization, the extensionconfigures the OpenCL environment at the beginning of a render process,in order to stand in the sandbox of Chromium and avoids potential attacks.It also loads the OpenCL library dynamically and handles relevant errors,to ensure that the system can be compiled and used on differentplatforms.After implementing the above parallel JavaScript extension, thisarticle analyzed the internal designs of V8JavaScript engine and explored again from another angle. Based on this knowledge, this article designedthe overall framework of parallel JavaScript system inside V8. To bemore specific, it refined the parallel interfaces and designed appropriatedata decomposition modes, as well as added a thread pool to V8engine,which can manages the synchronization and collaboration of differentthreads and avoids unnecessary overhead by delayed creation of workerthreads.Finally, this article tested the implemented parallel extension viasome practical JavaScript programs, and analyzed the factors thatinfluence the performance of programs, including the number ofprocessor cores, data size, running times and the parallel potential ofprograms. At last, this article gives the usage scenarios of theimplemented parallel JavaScript system.In conclusion, this article implemented a parallel JavaScriptextension which can significantly improve the performance ofcompute-intensive JavaScript programs, help programmers to write morecomplex web applications and improve the user experience, and hascertain practical value. |