Javascript code-javascript

Source: Internet
Author: User
With the popularization of multi-core CPUs, concurrent multi-thread operations are becoming increasingly popular in mainstream programming languages, but currently Javascript implementations do not yet support multithreading in terms of languages, I hope there will be great changes in language in the future. next I will give my personal opinion on how parallel operations will support front-end javascript.

1. Unlikely Evolution

Display thread support
If the display thread is supported in Javascript, it may be a disaster. Currently, browsers parse Javascript and execute it all in the ui thread of the browser.
For example, if you can run while (true) in Javascript, the browser interface will stop responding. or through my previous article (compiling Javascript Engine, providing sleep for JavaScript: http://www.cnblogs.com/ioriwellings/archive/2010/08/16/1800416.html) to understand how the UI is blocked.
In addition, if it is displayed that the support thread will certainly support the synchronization primitive function of data synchronization between threads, this problem will occur:
Get the lock in one function and release the lock in another function. But what if another function fails or another function is referenced from another file, it also happens that the file is not loaded due to some reasons (network problems, encoding problems), and a deadlock will occur.
Therefore, based on the above reasons, it is not realistic to display threads in JavaScript.

2 possible evolution

Implicit parallel support
Similar to the macro commands of openMP,
The following Code declares a parallel operation FOR a loop:

The Code is as follows:


# Pragma omp parallel
For (I = 0; I <N; I ++)
A [I] = 2 * I;


This method can avoid various troubles. parallel operations are hosted in the Javascript engine. Therefore, the Javascript engine has more space to process and optimize these parallel operations, such as calling openMP internally, parallel functions of Intel TBB.
So I guess this method will probably be used.

3. Handling parallel exceptions

Because Javascript code is implicitly hosted in parallel thread processing, you may not immediately get the exception status of a thread. Instead, you will not know that some code has an exception until all the threads have finished running.

4 Evolution of Debugger

A thread-aware Javascript debugger is generated to analyze information in each thread and freeze/resume the running of a thread.
Of course, debuggers similar to firebug written using Javascript scripts will also be much improved, but I think it is better that local application debuggers will become mainstream, such: visual studio.

5 conclusion

Parallel operations will affect the execution performance of Javascript on the front end. Many front-end effects written in Javascript will change and improve the performance of Javascript games. But will I see this change in javascript?

If you cannot wait, you can compile the existing js engine, add parallel operation interfaces, and release your own browser so that you can download the multi-core functions.

But it must be compatible with the current javascript specification. Otherwise, other browsers will not be able to recognize your code. Therefore, you must analyze the original serial code in the js engine and make it accurate, it can be converted into parallel code for optimization. I think this task is still very tough.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.