mithi / hexapod

Blazing fast hexapod robot simulator for the web.
https://hexapod.netlify.app
Apache License 2.0
579 stars 70 forks source link

Custom Partial Plotly Bundle to Reduce Bundle Size Further #135

Closed mithi closed 3 years ago

mithi commented 4 years ago

Full discussion in: https://github.com/plotly/plotly.js/issues/5031

mithi commented 4 years ago
Screen Shot 2020-07-31 at 12 50 53 AM
mithi commented 4 years ago

Attempting to reduce bundle size further https://github.com/mithi/hexapod/issues/55

mithi commented 4 years ago

Base

Screen Shot 2020-07-31 at 2 07 34 AM

After using custom bundle

import Plotly from "plotly.js/lib/core";
import Scatter3d from "plotly.js/lib/scatter3d"
import Mesh3d from "plotly.js/lib/mesh3d"

import createPlotlyComponent from "react-plotly.js/factory";
Plotly.register([Scatter3d, Mesh3d]);

const CustomPlotly = createPlotlyComponent(Plotly);
export default CustomPlotly;
Screen Shot 2020-07-31 at 1 59 52 AM

After splitting custom bundle

Screen Shot 2020-07-31 at 4 57 38 PM

When you split the core plotly module from others

        import("plotly.js/lib/core").then(Plotly => {
            Plotly.register([Scatter3d, Mesh3d])
            this.Plot = createPlotlyComponent(Plotly)
        })
mithi commented 4 years ago

Base

Screen Shot 2020-07-31 at 2 04 05 AM

Custom Bundle

Screen Shot 2020-07-31 at 1 56 32 PM

Custom Bundle Split

89007002-7bfd8e80-d33a-11ea-9712-805a4a537ffa
mithi commented 4 years ago

This is the result of splitting to two bundles 312.71 KB and 115.61 KB

Screen Shot 2020-07-31 at 5 59 56 PM Screen Shot 2020-07-31 at 5 51 32 PM
. .
mithi commented 4 years ago

With a 414kb bundle this is the performance

Screen Shot 2020-07-31 at 4 26 48 PM Screen Shot 2020-07-31 at 4 27 46 PM
. .

With 450kb bundle this is the performance

Screen Shot 2020-07-31 at 6 11 12 PM Screen Shot 2020-07-31 at 6 14 14 PM
. .
mithi commented 4 years ago

Netlify Performance (450kb)

Screen Shot 2020-07-31 at 6 21 10 PM Screen Shot 2020-07-31 at 6 22 06 PM Screen Shot 2020-07-31 at 6 23 21 PM
. . .

Netlify Custom Split Bundle Performance (300kb + 115kb)

Screen Shot 2020-07-31 at 6 52 33 PM Screen Shot 2020-07-31 at 6 56 26 PM Screen Shot 2020-07-31 at 6 47 43 PM
. . .
mithi commented 3 years ago

The best way to reduce bundle size is to use a smaller library such as https://github.com/mithi/bare-minimum-3d