Part 6 - Write Fast JavaScript

Sign in to queue

Description

How to write good and fast JavaScript? In this episode, we will show you how to initialize JavaScript on demand and how to work efficiently with JSON, .innerHTML,, numbers, arrays, and DOM objects.

Creating high performance sites and apps is crucial for every developer. In this series, we will explore the best practices, strategies, and performance tips and tricks, for writing fast JavaScript, measuring performance, improving responsiveness, optimizing media usage, and managing memory efficiency to make your apps running faster and fluid. Come learn the tips, tricks, and tools for maximizing the performance of your modern websites and apps with JavaScript and HTML5.

See the rest of episodes at Practical Performance Tips to Make Your HTML/JavaScript Faster

Embed

Download

Download this episode

The Discussion

  • User profile image
    Charles

    Hi Dr Chen

    I went to check out how re-defined array size can help with the speed. I used edge to test. The code is as follows

    let size = 10000000;
    let a = new Array();

    let startTime1 = new Date();
    for(let i = 0; i< size; i++){
    a[i] = 'hi';
    }

    let endTime1 = new Date();
    let slow = endTime1.getTime() - startTime1.getTime();
    a = undefined;
    console.log(slow);

    as you can see, the next step I took was to actually pass "size" into the array declaration and see the console value. It turns out,the actually timing is around 6 seconds for both. The faster one is faster by 200ms.

    So my question is, in what situation will this perfomance actually make a difference? I tried to use 1 billion, the browser will just crash. Hence I don't see an actual case where pre-defined array size will make a difference.

  • User profile image
    matteocontr​ini

    This is not properly writing faster JavaScript. This is often creating a big mess with code that's less easy to understand and that won't probably pass some linters.

Add Your 2 Cents