One . Reduce the level of judgment

As you can see from the code below , The same reduction in effect judgment levels can optimize performance

Two . Reduce the scope chain lookup level

A simple explanation , The first one in the figure below runs foo function ,bar Print in function name,bar There is no name, So the scope chain looks up ,foo Internal name,

But it's actually an assignment , And look up , In the global scope name, Compared to the figure below, the second , More than one level up , So it's going to take a little longer .

( remarks : Regardless of memory consumption , It depends on the product .)

3、 ... and . Reduce the number of data reads

A simple explanation , For multiple frequent calls , For example, array , The object is relatively slow , Because according to the reference relationship, we first need to find the location in the heap memory , So reduce the consumption of time ,

You should reduce the number of times you find members , For example, cache it in a variable ( remarks : Regardless of memory consumption , It depends on the product .)

Four . Literal quantity and construction

A simple explanation , The first one in the picture new Object() It's equivalent to calling a function , It's slow , The second one in the figure below is equivalent to opening up space in the heap area , Put attributes and values in it

So .

Again, for example , The first one in the figure below is just a literal string , And the second one creates a string object .

5、 ... and . Cycle optimization

A simple explanation : In Figure 2, a frequently used value is cached , Improve the efficiency of implementation .

As shown in the figure below : Regardless of order ,while Cyclic decrement ratio for loop , More efficient execution

6、 ... and . Reduce the number of statements and statements

A brief explanation : For infrequently used data , Caching first is not recommended , Get it when you execute it , To reduce memory consumption during execution, there is a compilation process before running , expression

It's more , We should split words into lexical units , Then do a grammar analysis , Then turn it into code and execute it , Time is wasted here .

Reduce the number of declared variables, as explained above

Talking about JavaScript Code performance optimization 2 More articles about

  1. [ original ] Talking about H5 Page performance optimization method

    [ original ] Talking about H5 Page performance optimization method The former company H5 Page performance test , Some performance bottlenecks were also found during the test , Now let's talk about H5 Page performance optimization , Just some common H5 Page performance optimization measures , Actually sum Web Page performance optimization ideas ...

  2. JavaScript Summary of code performance optimization

    JavaScript Summary of code performance optimization Try to use the original method javaScript It's an explanatory language , It's slower than compiled languages . Browser has been implemented , Don't do it again . in addition , The method that the browser has implemented is in the aspect of algorithm ...

  3. Talking about webpack4.0 performance optimization ( turn )

    Preface : In real projects , We may rarely need to configure one from scratch webpack project , especially webpack4.0 After release , Zero configuration starts a project and becomes a standard configuration . Because of zero configuration webpack To the project itself “ pack ” and “ ...

  4. Talking about Oracle The goal of database performance optimization

    Oracle Performance optimization guarantees Oracle The robustness of the database , In order to ensure Oracle The database runs in the best performance state , Before the development of information system, we should consider the optimization strategy of database . Distinguish from the scenario of database performance optimization , Performance optimization can be divided into such categories as ...

  5. Talking about web Front end performance optimization

    Front end performance optimization : One . Minimize the front end http request . 1. Merge optimization script files and css file . 2. Try to put the same kind of background together , use css Control display . Two . Use browser cache . If you can force the browser to cache locally , Will decrease ...

  6. BizTalk Development series ( Thirty-two ) Talking about BizTalk Host performance optimization

    quite a lot BizTalk All projects should consider the problem of performance optimization , although BizTalk Using multithreading to process messages , Greatly improve the efficiency of the program . But by default BizTalk The host has many blocking parameters to control BizTalk Resource utilization of the server , ...

  7. Talking about Vue Project performance optimization Experience

    I'd like to summarize a few points about optimizing the company's projects : 1. Look at the size of the imported image first , If it's too big , Can be compressed , Compress path :https://zhitu.isux.us/ 2. Package optimization , After the completion of the next project development . Package the source code online , You need to check ...

  8. 【 turn 】JavaScript Summary of code performance optimization

    The author of this article :zifan come from : Ctrip Design Committee link :http://ued.ctrip.com/blog/javascript-code-performance-optimization-summary. ...

  9. JavaScript Summary of code performance optimization

    In this paper, from :http://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=400360237&idx=2&sn=eb00241cb3b ...

  10. Talking about MySQL Database performance optimization

    MySQL The database is IO Intensive program , Like other databases , The main function is data persistence and data management . This paper focuses on optimizing MySQL Database cache parameters such as query cache , Table cache , Log cache , The index buffer ,innodb cache ...

Random recommendation

  1. 3d Picture switching (css3 Frame animation )

    Effect with dither flip hidden , Use frame animation <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...

  2. hdu 1061 Fast power

    seek n^n A bit of Sample Input 2 3 4 Sample Output 7 6 Direct fast exponentiation , Pay attention to long long #include<cstdio> long long q ...

  3. 6、 ... and JSP and Servlet The system tuning skills of

    Method 1 : stay Servlet Of init() Function to apply buffer data Method 2 : prohibit Servlet and JSP Automatic overloading of : Servlet/JSP Provides a practical technology , Automatic overloading technology , It provides developers with ...

  4. Security video 4G The flow of transmission , Hikvision camera related settings

    Our current rtsp The video solution is as follows : camera <---------->NVR( adopt 4G Upload )<---------->easydarwin<----------> Their own ...

  5. Associated query a small table . Does it affect performance (mysql)

      Specific sentences   SELECT dfm.id, dfm.member_code, dfm.member_name, dfm.recommend_code, dfm.member_rank, dfm.cre ...

  6. utilize PreLoader Realize a head up display (HUD) effect ( Can be applied to load wait effect ), And give a simple explanation

    What is? PreLoader? PreLoader By Volodymyr Kurbatov A very interesting design HUD( Head up display (Head Up Display)), Through the sticky animation between the moving stain and the fixed stain ...

  7. Configuring High Availability and Consistency for Apache Kafka

    To achieve high availability and consistency targets, adjust the following parameters to meet your r ...

  8. php expression

    Expression is PHP An important concept in , The expression can be understood as “ Anything of value ”. In this tutorial, we'll cover the syntax of expressions , We use “expr” To represent the expression . Here's an expression : $x > $y; In the example above , When $ ...

  9. Get device information —— Get the client ip Address and mac Address

    1. Access to the local IP( It could be Intranet IP,192.168.xxx.xxx) /** * Access to the local IP * * @return */ public static String getLocalIpAddre ...

  10. CentOS 7.4 yum install LAMP Environmental Science

    Configure firewall , Turn on 80.3306 port .CentOS 7.0 The default is firewall As a firewall , Here instead iptables A firewall . # stop it firewall service systemctl stop firewa ...