2.4.26 • Published 10 months ago

@hint/hint-performance-budget v2.4.26

Weekly downloads
365
License
Apache-2.0
Repository
github
Last release
10 months ago

Performance budget (performance-budget)

A web performance budget is a group of limits to certain values that affect site performance that should not be exceeded in the design and development of any web project. This could be the total size of a page, size of images you are uploading, or even the number of HTTP requests that your webpage generates.

keycdn - web performance budget

Why is this important?

As of January 2018, the average size of a website is 3,545kB:

image

Although the global average connection is 7.2Mb/s (check Akamai's state of the Internet 2017), "no bit is faster than one that is not sent" (quote by Ilya Grigorik). Web developers need to be mindful not only about the size of their sites, but also the number of requests, different domains, third party scripts, etc. The time required by a browser to download a 200kB file is not the same as 20 files of 10kB.

What does the hint check?

This hint calculates how long it will take to download all the resources loaded initially by the website under a 3G Fast network (but that can be changed, see "Can the hint be configured?" section). If the load time is greater than 5 seconds, the hint will fail.

To calculate the final load time, some assumptions and simplifications are done. While the real numbers might be different, the results should provide enough guidance to know if something needs more attention.

The reason for using predefined conditions and assumptions are:

  • Guarantee consistent results across runs. If a website serves the same assets, the results should be the same.
  • Show the impact in load time of each transmitted byte with the goal of reducing the number and size of resources downloaded (first and third party).

The simplified formula to calculate the time is:

Time = (total number of requests * RTT) +
       (number of different domains * RTT) +
       (number of different secured domains * RTT) +
       (number of redirects * RTT) +
       (total number of requests * TCP slow-start phase) +
       (total size of resources / bandwidth)

This is the list of things considered:

  • Everything is a first load, no values are cached, and no connections are opened.
  • RTT (Round-Trip Time) is fixed and changes depending on the configured network. It assumes all servers respond instantly and in the same amount of time.
  • DNS lookup: Every hostname resolution requires 1 RTT, imposing latency on the request and blocking the request while the lookup is in progress.
  • TCP handshake: Each request requires a new TCP connection. TCP connections require 1 RTT before starting to send information to the server. There's no connection reuse and the maximum number of connections to a domain (usually 6) is ignored.
  • TCP slow-start phase: The values used to calculate the duration are:
    • cwnd: 10 network segments
    • rwnd: 65,535 bytes (no TCP window scaling)
    • segment size: 1460 bytes After this phase, the full bandwidth of the connection is used to download the remaining.
  • TLS handshake: New TLS connections usually require two roundtrips for a "full handshake". However, there are ways of requiring only 1 RTT like TLS False Start and TLS Session Resumption. This hint assumes the optimistic scenario.
  • Redirects: We simplify the redirects and assume the connection is reused and to the same server. If the redirect is to another domain, the penalty will be even greater.
  • The server doesn't use HTTP/2.

Can the hint be configured?

You can change the type of connection and/or the target load time in the .hintrc file, using something such as the following:

{
    "connector": {...},
    "formatters": [...],
    "hints": {
        "performance-budget": ["error", {
            "connectionType": "Dial",
            "loadTime": 10
        }],
        ...
    },
    ...
}

The possible values and the associated speeds for connectionType are:

ValueInOutRTT
FIOS20 Mbps5 Mbps4ms
LTE12 Mbps12 Mbps70ms
4G9 Mbps9 Mbps170ms
Cable5 Mbps1 Mbps28ms
3G1.6 Mbps768 Kbps300ms
3GFast1.6 Mbps768 Kbps150ms
DSL1.5 Mbps384 Kbps50ms
3GSlow400 Kbps400 Kbps400ms
3G_EM400 Kbps400 Kbps400ms
2G280 Kbps256 Kbps800ms
Edge240 Kbps200 Kbps840ms
Dial49 Kbps30 Kbps120ms

loadTime needs to be a number greater than 1 and indicates the time in seconds to load all the resources.

The default values are:

  • connectionType: 3GFast
  • loadTime: 5

This means that if the user changes the connectionType but not the loadTime, the hint will use 5 as the target.

Examples that trigger the hint

  • Any combination of sizes, redirects, requests to different domains, etc. that make the site load after 5s on a 3GFast network using the established formula.

Examples that pass the hint

  • Any combination of sizes, redirects, requests to different domains, etc. that make the site load in or under 5s on a 3GFast network using the established formula.

How to use this hint?

To use it you will have to install it via npm:

npm install @hint/hint-performance-budget

Note: You can make npm install it as a devDependency using the --save-dev parameter, or to install it globally, you can use the -g parameter. For other options see npm's documentation.

And then activate it via the .hintrc configuration file:

{
    "connector": {...},
    "formatters": [...],
    "hints": {
        "performance-budget": "error",
        ...
    },
    "parsers": [...],
    ...
}

Further Reading

2.4.26

10 months ago

2.4.25

11 months ago

2.4.24

1 year ago

2.4.23

2 years ago

2.4.22

2 years ago

2.4.19

2 years ago

2.4.21

2 years ago

2.4.20

2 years ago

2.4.18

2 years ago

2.4.17

2 years ago

2.4.16

2 years ago

2.4.15

2 years ago

2.4.14

2 years ago

2.4.13

2 years ago

2.4.12

3 years ago

2.4.11

3 years ago

2.4.10

3 years ago

2.4.9

3 years ago

2.4.8

3 years ago

2.4.7

3 years ago

2.4.6

4 years ago

2.4.5

4 years ago

2.4.4

4 years ago

2.4.3

4 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.11

5 years ago

2.3.10

5 years ago

2.3.9

5 years ago

2.3.8

5 years ago

2.3.7

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-beta.0

6 years ago