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: Remove antd-with-locales import #29788

Merged
merged 4 commits into from
Aug 5, 2024

Conversation

kgabryje
Copy link
Member

SUMMARY

We were importing a huge package antd-with-locales (over 4MB) just to pick 1 locale for DatePicker from it.
This PR removes that import and lazy loads just the required locale.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

Screenshot 2024-07-31 at 15 48 00

After:

Screenshot 2024-07-31 at 15 43 44

TESTING INSTRUCTIONS

  1. Add a time filter to a dashboard
  2. Switch to "Custom frame"
  3. Open a date picker
  4. Should work like before

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot bot added the change:frontend Requires changing the frontend label Jul 31, 2024
@kgabryje kgabryje force-pushed the perf/remove-antd-with-locales branch from 5ff7440 to 93d7200 Compare July 31, 2024 16:25
@rusackas
Copy link
Member

Loving these! Here are some suggestions (take 'em or leave 'em) that I came up with totally on my own with no help.

Potential concerns:

  • There might be a brief moment where the component doesn't render while the locale is being loaded
  • Error handling for failed locale imports could be improved

Suggestions for improvement:

  • Consider adding a loading state instead of returning null when datePickerLocale is null
  • Add error handling for the locale import promise to gracefully handle failed imports
  • Consider memoizing the effect dependency array to prevent unnecessary re-runs of the effect

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

Potential enhancements on the thread, but I love it. LGTM.

@mistercrunch mistercrunch added the dashboard:performance Related to Dashboard performance label Jul 31, 2024
Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

LGTM! Thinking of ways to prevent this, but I can totally see how whoever brought this npm library having no indication of the impact on the bundle.

Let's think about what CI automation we'd like to have in place to alert author/reviewers about bundle size changes. Let me start a discussion thread about it.

@mistercrunch
Copy link
Member

Started a GH discussion about preventing bundle size creep using CI here -> #29803

@kgabryje
Copy link
Member Author

kgabryje commented Aug 1, 2024

Had to bump @testing-library/react - our version had a bug which caused waitForElementToBeRemoved to be flaky

@hainenber
Copy link
Contributor

hainenber commented Aug 1, 2024

@kgabryje I think your PR's lockfile has slipped out the required @nx dependencies 👀

This is in the master branch (6 search results with dependencies in node_modules)
image

This is in your PR's branch (only 2 search results without the ones in node_modules)
image

@kgabryje
Copy link
Member Author

kgabryje commented Aug 1, 2024

@kgabryje I think your PR's lockfile has slipped out the required @nx dependencies 👀

Oh that's interesting... I only bumped a tests library. I'll try to regenerate package-lock and see if it helps. Thanks!

@kgabryje
Copy link
Member Author

kgabryje commented Aug 4, 2024

Looks like it's related to this bug. I generated the package-lock file on my M2 macbook, and only arm64 references were generated. I fixed it by removing package-lock.json AND node_modules before rerunning npm-install

@kgabryje kgabryje force-pushed the perf/remove-antd-with-locales branch 3 times, most recently from 9eb5b43 to 59207fa Compare August 4, 2024 12:38
@github-actions github-actions bot removed the packages label Aug 4, 2024
@kgabryje kgabryje force-pushed the perf/remove-antd-with-locales branch from 59207fa to 3782273 Compare August 4, 2024 12:43
@hainenber
Copy link
Contributor

hainenber commented Aug 4, 2024

<off-topic>

Looks like it's related to npm/cli#4828. I generated the package-lock file on my M2 macbook, and only arm64 references were generated. I fixed it by removing package-lock.json AND node_modules before rerunning npm-install

Thanks @kgabryje for going through and find the underlying RC! This seems precarious and I couldn't help but wonder if migrating to yarn could help alleviating this if not going with Lerna downgrade approach. Maybe a little too "overkill" though. Wdyt?

Edit: according to this comment in the linked issue, upgrading to currently latest npm version, v10.8.2, could help with the mitigation 🤔

</off-topic>

@kgabryje
Copy link
Member Author

kgabryje commented Aug 4, 2024

Edit: according to this comment in the linked issue, upgrading to currently latest npm version, v10.8.2, could help with the mitigation 🤔

I did all that with the latest npm version 🙁 A quick (and a bit dirty) fix might be to nx-linux-x64-gnu as Superset dependency - I noticed that @eschutho had a similar problem in another PR some time ago, so I'm not the only one

@kgabryje kgabryje force-pushed the perf/remove-antd-with-locales branch from 2d6c934 to f2fdbf3 Compare August 5, 2024 14:01
@kgabryje kgabryje merged commit f1136b5 into apache:master Aug 5, 2024
34 checks passed
@eschutho
Copy link
Member

eschutho commented Aug 5, 2024

I did all that with the latest npm version 🙁 A quick (and a bit dirty) fix might be to nx-linux-x64-gnu as Superset dependency - I noticed that @eschutho had a similar problem in another PR some time ago, so I'm not the only one

The missing optional dependency should be fixed in @mistercrunch's PR, but this package by default will only put into the lockfile the required optional dependencies per the machine that was used to build the lockfile. The docker image recreates the package-lock file, but this may be an issue in the future with pypi or official release tarballs.

-- edit --
I just looked at the package-lock file and all the OSs are included for @nx as optional.

WanjohiWanjohi pushed a commit to IDinsight/surveystream_superset_source that referenced this pull request Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:frontend Requires changing the frontend dashboard:performance Related to Dashboard performance dependencies:npm packages plugins size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants