|
| 1 | +## Performance |
| 2 | +This section can be skipped at first reading. You might prefer go back to the [README](../../README.md). |
| 3 | +### Benchmarks |
| 4 | +To benchmark the solution perform the following steps: |
| 5 | + |
| 6 | +1. If the [Getting Started](../../README.md#getting-started) section has been completed, skip this step. Otherwise clone the repository and build the solution: |
| 7 | + ``` |
| 8 | + git clone https://github.com/winwiz1/crisp-react.git |
| 9 | + cd crisp-react |
| 10 | + yarn install && yarn build:prod |
| 11 | + ``` |
| 12 | +2. Start the backend: |
| 13 | + ``` |
| 14 | + yarn run:prod |
| 15 | + ``` |
| 16 | +
|
| 17 | +3. Start Chrome and open new incognito window to disable extensions. Point it to `localhost:3000.` The Overview page should appear. |
| 18 | +
|
| 19 | +4. Press F12 to open Chrome DevTools, then activate the `Audits` tab. Choose the settings: |
| 20 | + ``` |
| 21 | + Device: Desktop |
| 22 | + Audits: Performance |
| 23 | + Throttling: No throttling |
| 24 | + Clear storage: ticked |
| 25 | + ``` |
| 26 | +5. Run the audit. Then change `Throttling` to `Simulated Slow 4G, 4x CPU Slowdown` and run the audit again. The results should be similar to shown in the table: |
| 27 | + |
| 28 | + | Throttling | Benchmark Results | |
| 29 | + | :---:| :---:| |
| 30 | + | not throttled |  | |
| 31 | + | throttled to slow 4G,<br/>CPU slowdown |  | |
| 32 | + |
| 33 | + As you can see, throttling results in 16% performance drop only. Switching from Desktop to Mobile produces slightly longer First Meaningful Paint and other metrics with the same performance scores. |
| 34 | + |
| 35 | +6. Terminate the backend by pressing `Control+C`. |
| 36 | + |
| 37 | +### Future Considerations |
| 38 | +The solution has a limited amount of code, as a boilerplate should. It begs a question to what extent the performance will be affected when the application grows. To contemplate an answer let's have a look at the script bundles: |
| 39 | + |
| 40 | +| Bundle | Description | Brotli-compressed size in production build / development build size |
| 41 | +| :---:| :---| :---:| |
| 42 | +| `first.<hash>.js` | Renders the SPA called 'first' | 6 Kb / 64 Kb | |
| 43 | +| `second.<hash>.js` | Renders the SPA called 'second' | 8 Kb / 24 KB | |
| 44 | +| `vendor.<hash>.js` | Contains dependencies from `client/node_modules/`. Reused among SPAs. | 77 Kb / 3.6 MB| |
| 45 | +| `runtime.<hash>.js` | Webpack utility bundle. Contains internal webpack code. Reused among SPAs. | 2 Kb / 7 Kb | |
| 46 | + |
| 47 | +>Sidenote. The bundles are located in the `client/dist` directory created during builds. We take Brotli compression (with `.br` file extension) into account because on the one hand it delivers approximately 17% better compression than gzip and on the other hand all modern browsers support it and have supported it for quite a while. Some bundles are too small to benefit from compression and are left uncompressed in which case we take the uncompressed size. |
| 48 | +
|
| 49 | +>To inspect bundle sizes in different builds, switch between development and production by executing `yarn build` or `yarn build:prod` from the `client/` subdirectory. |
| 50 | +
|
| 51 | +Let's assume that at the beginning of the development the second SPA and its bundle were removed (by commenting it out in the SPA Configuration) so the React app contains a single SPA only called 'first'. With the anticipated application growth the `first` bundle is expected to grow rapidly to reflect the expanding functionality and codebase. The `vendor` bundle is expected to grow at much slower pace because it already contains the bulk of dependencies (project dependencies including the React library, its direct dependencies, dependencies of the dependencies and so forth). |
| 52 | + |
| 53 | +No substantial impact on the performance can be anticipated until the `first` bundle reaches the size and then outgrowths the `vendor` bundle. At this point it might be a good time to use code splitting and introduce another SPA. One of the goals of using multiple SPAs is to ensure each SPA is rendered by its own and smaller bundle thus reducing React application loading time. See [SPA Configuration](../../README.md#spa-configuration) section for more details. |
| 54 | + |
| 55 | +The conclusion is that with multiple SPAs you can grow the functionality and codebase while maintaining the top performance. |
| 56 | + |
| 57 | +--- |
| 58 | +Back to the [README](../../README.md). |
0 commit comments