Javascript efficiency tuning experience

Source: Internet
Author: User

1. Put the definition of the number of cycles in the external body of the Loop: It seems that all languages are the same, and the effect on more than 100 elements is becoming more and more obvious. That is to say, for (VAR I = 0; I <arrdata. length; I ++) to for (VAR I = 0, Len = arrdata. length; I <Len; I ++) greatly improves the performance, because it avoids the calculation of length every cycle. In addition, some foreigners claim that a descending cycle is faster, that is, for (VAR I = arrdata. Length-1; I> = 0; I --). After testing, I found that the efficiency is not much different from that of the ascending cycle.
2. Change the multi-layer object reference to a shorter path reference: In JavaScript, this problem is very obvious, such as the proposalno domain var proposalnofield = FM. proposalno. There is a huge difference between proposalnofield. Value and FM. proposalno. value in a loop (more than 100 times. Therefore, try to shorten the access path by using intermediate variables.
3. Impact of third-party JavaScript packages: Because JavaScript supports prototype, such as prototype. JS, it modifies some of the behavior of array and sometimes writes CodeThere is no problem, but if the prototype is modified, the problem also occurs. For example, the prototype. js version 1.4 has a bug. In some cases, array sorting will lead to an endless loop.

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.