Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: reduce the bundle size, vol. 2 #24969

Merged
merged 21 commits into from
Jul 16, 2023
Merged

Conversation

iamakulov
Copy link
Contributor

@iamakulov iamakulov commented Jun 30, 2023

Description

This PR takes the second (and last) round on reducing the bundle size. Specifically, it:

  • reverts a regression that caused Lodash to be bundled in full
  • code-splits away Uppy, react-json-view, and the welcome tour app.json
  • removes moment-timezone (only from the main thread code) and unused code syntax highlighter definitions

This makes the bundle another 15% smaller (5.42 MB → 4.64 MB minified). In total, since the first PR, we’ve shaved off 49% of the bundle (9.01 → 4.64 MB minified)!

Here’s the bundle before the change (with removed and code-split modules highlighted):

Screenshot 2023-06-30 at 13 10 25

Note: this PR relies on appsmithorg/design-system#514 to fully code-split Uppy away.

Type of change

  • Chore (housekeeping or task changes that don't impact user perception)

Testing

How Has This Been Tested?

  • Manual: deep testing of the new File Picker, smoke testing of the guided tour and other changes
  • Jest
  • Cypress

Test Plan

Issues raised during DP testing

Checklist:

Dev activity

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • PR is being merged under a feature flag

QA activity:

  • Speedbreak features have been covered
  • Test plan covers all impacted features and areas of interest
  • Test plan has been peer reviewed by project stakeholders and other QA members
  • Manually tested functionality on DP
  • We had an implementation alignment call with stakeholders post QA Round 2
  • Cypress test cases have been added and approved by SDET/manual QA
  • Added Test Plan Approved label after Cypress tests were reviewed
  • Added Test Plan Approved label after JUnit tests were reviewed

@iamakulov iamakulov requested a review from a team June 30, 2023 11:25
@iamakulov iamakulov requested a review from KelvinOm as a code owner June 30, 2023 11:25
@iamakulov iamakulov requested review from sbalaji1192 and removed request for a team June 30, 2023 11:25
@iamakulov
Copy link
Contributor Author

/ok-to-test

@github-actions
Copy link

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5422397678.
Workflow: Appsmith External Integration Test Workflow.
Commit: ``.
PR: 24969.
Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5422397678_1

@github-actions
Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5422397678.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/BugTests/AllWidgets_Reset_Spec.ts

  2. cypress/e2e/Regression/ClientSide/Widgets/CurrencyInput/CurrencyInput_spec.js
  3. cypress/e2e/Regression/ClientSide/Widgets/ListV2/Childwigets/List_Inputs_spec.js
To know the list of identified flaky tests - Refer here

@iamakulov
Copy link
Contributor Author

iamakulov commented Jul 2, 2023

Flaky tests? Let’s try again Not flaky :)

@iamakulov
Copy link
Contributor Author

/ok-to-test

@github-actions
Copy link

github-actions bot commented Jul 2, 2023

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5438070567.
Workflow: Appsmith External Integration Test Workflow.
Commit: ``.
PR: 24969.
Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5438070567_1

@github-actions
Copy link

github-actions bot commented Jul 2, 2023

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5438070567.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/BugTests/AllWidgets_Reset_Spec.ts

  2. cypress/e2e/Regression/ClientSide/Git/GitSync/GitSyncedApps_spec.js
  3. cypress/e2e/Regression/ClientSide/Widgets/CurrencyInput/CurrencyInput_spec.js
  4. cypress/e2e/Regression/ClientSide/Widgets/ListV2/Childwigets/List_Inputs_spec.js
To know the list of identified flaky tests - Refer here

@iamakulov
Copy link
Contributor Author

/ok-to-test

@github-actions
Copy link

github-actions bot commented Jul 2, 2023

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5439060915.
Workflow: Appsmith External Integration Test Workflow.
Commit: ``.
PR: 24969.
Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5439060915_1

@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5439060915.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/OtherUIFeatures/Omnibar_spec.js

To know the list of identified flaky tests - Refer here

@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5439060915.
Commit: ``.
Cypress dashboard url: Click here!
All cypress tests have passed 🎉🎉🎉

@@ -1,5 +1,5 @@
import { BaseQueryGenerator } from "../BaseQueryGenerator";
import { format } from "sql-formatter";
import { formatDialect, postgresql } from "sql-formatter";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamakulov , why is this change required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s because sql-formatter bundles a whole lot of dialect formatters, by default – and we only need one of them: sql-formatter-org/sql-formatter#452

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Looks like these were added recently during a recent merge. Thanks for the catch – I’ll update them and add a ESLint rule as well.

@@ -1,3 +1,53 @@
// 🚧 NOTE: this file exists only for the worker thread, as the worker thread needs to pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid a full lodash load can we use this eslint rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm so right now we’re relying on babel-plugin-lodash to avoid full Lodash imports. Do you mean replacing babel-plugin-lodash with eslint-plugin-lodash, or using one in addition to another?

(If the former: I moderately prefer babel-plugin-lodash to ESLint rules. The former works everywhere, whereas the latter is one // eslint-disable-next-line away from bundling the full Lodash again. But if you feel this lodash-wrapper.js thingy is too much complexity, I’m happy to reconsider!)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using eslint-plugin-lodash in addition to babel-plugin-lodash.

If I understand correctly what is going on here, then when using the eslint-plugin-lodash, we will have to correct the imports and everything related to lodash-wrapper.js will become easier, right?

Copy link
Contributor Author

@iamakulov iamakulov Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. So, on a second thought, I think eslint-plugin-lodash are babel-plugin-lodash aren’t really compatible:

eslint-plugin-lodash vs babel-plugin-lodash

eslint-plugin-lodash forces developers to do this change:

// Before
import _ from "lodash"
_.map()

// After
import map from "lodash/map"
map()

But that’s pretty much what babel-plugin-lodash does automatically! We can either force the developers to change all imports themselves (with eslint-plugin-lodash), or we can use babel-plugin-lodash to do that automatically, but using both of them doesn’t make much sense.

Why lodash-wrapper.js exists

The reason lodash-wrapper.js exists is this:

/////////////////////////////////////////////////////////////////////////
//
// We use babel-plugin-lodash to only import the lodash functions we use.
// Unfortunately, the plugin doesn’t work with the following pattern:
// import _ from 'lodash';
// const something = _;
// When it encounters code like above, it will replace _ with `undefined`,
// which will break the app (https://github.com/lodash/babel-plugin-lodash/issues/235).
//
// Given that we *need* to use the full lodash in ./resetJSLibraries.js,
// we use this workaround where we’re importing Lodash using CommonJS require().
// It works because babel-plugin-lodash doesn’t support CommonJS require().
module.exports = require("lodash");

This is a workaround for a bug in babel-plugin-lodash.

If we use eslint-plugin-lodash together with babel-plugin-lodash, lodash-wrapper.js will still be needed – as babel-plugin-lodash will still be enabled and will still be introducing the bug.

If we use only eslint-plugin-lodash, lodash-wrapper.js won’t be needed anymore – we’ll be able to just // eslint-disable-next-line in the worker where we need to import full Lodash.

Tradeoffs

So, basically, here are the tradeoffs of each:

eslint-plugin-lodash babel-plugin-lodash
Requires the developer to change the import Changes the import automatically
More explicit (= easier to debug) More implicit (= harder to debug)
Easier to accidentally disable in some file Harder to accidentally disable in some file
(Probably) bug-free Has a non-obvious tricky bug with _ becoming undefined which we already stumbled upon
Doesn’t need lodash-wrapper.js Needs lodash-wrapper.js as a workaround for the above bug

I’m pretty neutral about which one to pick – which tradeoffs, do you think, matter more here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all thank you for such an answer. Excellent engineering approach! 👍

I would suggest using eslint-plugin-lodash as it is simpler and more obvious. I'm in favor of keeping things as simple as possible. So any new developer will be able to quickly figure out what's going on and make changes.

@riodeuno @SatishGandham need your comment here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second @KelvinOm 's opinion on this. More explicit (= easier to debug) had me sold.

What concerns me is this: Easier to accidentally disable in some file. How do we mitigate this? Any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[By “Easier to accidentally disable in some file”, by the way, I’m meaning it’s easy to do this:

// eslint-disable-next-line
import _ from "lodash"

If someone (e.g. an external contributor, or a new engineer who just joined the team) does this without understanding full implications of this, and it slips through the code review, it’d bump the bundle size immediately.

One way to catch this is to set up bundle size monitoring that triggers an alert if the bundle suddenly increases by X% (where X is 5-10%+). I like using SpeedCurve for that. Happy to guide you through that!]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to catch this is to set up bundle size monitoring that triggers an alert if the bundle suddenly increases by X% (where X is 5-10%+). I like using SpeedCurve for that. Happy to guide you through that!]

I'm sure we should set up bundle size monitoring anyway, not just because of lodash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deal! Then I’ll PR eslint-plugin-lodash as a separate PR, to avoid blocking this one 👍

@iamakulov iamakulov requested review from a team and rahulramesha and removed request for a team July 3, 2023 15:53
@SatishGandham
Copy link
Contributor

/ok-to-test

@github-actions
Copy link

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5532157983.
Workflow: Appsmith External Integration Test Workflow.
Commit: ``.
PR: 24969.
Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5532157983_1

@SatishGandham
Copy link
Contributor

/ok-to-test

@github-actions
Copy link

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5534349370.
Workflow: Appsmith External Integration Test Workflow.
Commit: ``.
PR: 24969.
Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5534349370_1

@github-actions
Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5534349370.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/Apps/EchoApiCMS_spec.js

  2. cypress/e2e/Regression/Apps/MongoDBShoppingCart_spec.ts
  3. cypress/e2e/Regression/ClientSide/Binding/TableV2TextPagination_spec.js
  4. cypress/e2e/Regression/ClientSide/BugTests/Bug22281_WelcomeTour_spec.ts
  5. cypress/e2e/Regression/ClientSide/Fork/ForkApplicationReconnectModal_spec.ts
  6. cypress/e2e/Regression/ClientSide/Git/ExistingApps/v1.9.24/DSCrudAndBindings_Spec.ts
  7. cypress/e2e/Regression/ClientSide/Onboarding/CreateNewApp_spec.js
  8. cypress/e2e/Regression/ClientSide/OtherUIFeatures/ApplicationURL_spec.js
  9. cypress/e2e/Regression/ClientSide/OtherUIFeatures/ExportApplication_spec.js
  10. cypress/e2e/Regression/ClientSide/ProductRamps/PrivateEmbedRamp_spec.ts
  11. cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePickerV2_Widget_Reskinning_spec.js
  12. cypress/e2e/Regression/ClientSide/Workspace/CreateAppWithSameNameInWorkspace_spec.js
  13. cypress/e2e/Regression/ClientSide/Workspace/MemberRoles_Spec.ts
  14. cypress/e2e/Regression/ClientSide/Workspace/ShareAppTests_spec.js
To know the list of identified flaky tests - Refer here

@iamakulov
Copy link
Contributor Author

↑ Very confused by all of these because

  • the FilePickerV2_Widget_Reskinning_spec.js issue is transient – I reproduced it once – but then I stopped being able to repro it
  • other failures are mostly about app rename suddenly not working?

Let me re-run.

@github-actions
Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5534349370.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Apps/EchoApiCMS_spec.js

  2. cypress/e2e/Apps/MongoDBShoppingCart_spec.ts
  3. cypress/e2e/ClientSide/BugTests/Bug22281_WelcomeTour_spec.ts
  4. cypress/e2e/ClientSide/Fork/ForkApplicationReconnectModal_spec.ts
  5. cypress/e2e/ClientSide/Git/ExistingApps/v1.9.24/DSCrudAndBindings_Spec.ts
  6. cypress/e2e/ClientSide/Onboarding/CreateNewApp_spec.js
  7. cypress/e2e/ClientSide/OtherUIFeatures/ApplicationURL_spec.js
  8. cypress/e2e/ClientSide/OtherUIFeatures/ExportApplication_spec.js
  9. cypress/e2e/ClientSide/ProductRamps/PrivateEmbedRamp_spec.ts
  10. cypress/e2e/ClientSide/Widgets/Filepicker/FilePickerV2_Widget_Reskinning_spec.js
  11. cypress/e2e/ClientSide/Workspace/CreateAppWithSameNameInWorkspace_spec.js
  12. cypress/e2e/ClientSide/Workspace/MemberRoles_Spec.ts
  13. cypress/e2e/ClientSide/Workspace/ShareAppTests_spec.js
To know the list of identified flaky tests - Refer here

@iamakulov
Copy link
Contributor Author

Still failing. I’m running a workshop on Thu so will investigate and fix on Fri 👍

@iamakulov
Copy link
Contributor Author

/ok-to-test

@github-actions
Copy link

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5558615534.
Workflow: Appsmith External Integration Test Workflow.
Commit: ``.
PR: 24969.
Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5558615534_1

@github-actions
Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5558615534.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePickerV2_Widget_Reskinning_spec.js

To know the list of identified flaky tests - Refer here

@github-actions
Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5558615534.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/FilePickerV2_Widget_Reskinning_spec.js

To know the list of identified flaky tests - Refer here

This ensures custom styles aren’t overridden by .uppy-u-reset from Uppy styles which is also present on the same nodes. (Right now, the order in which Uppy styles vs styled-components styles are inserted seems to be dependent only on the import structure/order.)
@iamakulov
Copy link
Contributor Author

/ok-to-test

@github-actions
Copy link

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5561357070.
Workflow: Appsmith External Integration Test Workflow.
Commit: ``.
PR: 24969.
Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5561357070_1

@github-actions
Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5561357070.
Commit: ``.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:


    To know the list of identified flaky tests - Refer here

    @iamakulov
    Copy link
    Contributor Author

    ↑ The issue should be fixed now!

    @github-actions
    Copy link

    Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5558615534.
    Commit: ``.
    Cypress dashboard: Click here!
    The following are new failures, please fix them before merging the PR:

    1. cypress/e2e/FilePickerV2_Widget_Reskinning_spec.js

    To know the list of identified flaky tests - Refer here

    1 similar comment
    @github-actions
    Copy link

    Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5558615534.
    Commit: ``.
    Cypress dashboard: Click here!
    The following are new failures, please fix them before merging the PR:

    1. cypress/e2e/FilePickerV2_Widget_Reskinning_spec.js

    To know the list of identified flaky tests - Refer here

    @iamakulov
    Copy link
    Contributor Author

    Okay, so it looks like my test run actually failed to run some tests (due to 429 Too Many Requests).

    We then re-ran the tests, but re-ran them with the outdated code – thus still including the issue I fixed in acdbc51:

    CleanShot 2023-07-16 at 16 24 15@2x

    To make sure we’re running the latest code from this branch, I’m going to trigger a fresh test run.

    @iamakulov
    Copy link
    Contributor Author

    /ok-to-test

    @github-actions
    Copy link

    Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/5568194657.
    Workflow: Appsmith External Integration Test Workflow.
    Commit: ``.
    PR: 24969.
    Perf tests will be available at https://app.appsmith.com/app/performance-infra-dashboard/pr-details-638dd7cd2913ba43778b915e?pr=24969&runId=5568194657_1

    @github-actions
    Copy link

    Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5568194657.
    Commit: ``.
    Cypress dashboard: Click here!
    The following are new failures, please fix them before merging the PR:

    1. cypress/e2e/Regression/ClientSide/Git/ExistingApps/v1.9.24/DSCrudAndBindings_Spec.ts

    To know the list of identified flaky tests - Refer here

    @github-actions
    Copy link

    Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/5568194657.
    Commit: ``.
    Cypress dashboard url: Click here!
    All cypress tests have passed 🎉🎉🎉

    @SatishGandham SatishGandham merged commit 8a1870d into release Jul 16, 2023
    9 checks passed
    @SatishGandham SatishGandham deleted the perf/bundle-size-v2 branch July 16, 2023 18:49
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Test Plan Approved Manual/Cypress tests covers changes made on the PR. Else, add skip-testPlan label if not applicable
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    8 participants