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

Optimize lodash use for tree-shaking #1828

Merged
merged 1 commit into from
May 20, 2024

Conversation

AMoo-Miki
Copy link
Contributor

Description

Optimize lodash use for tree-shaking: Not a huge impact but a necessary step. There are nearly 550 linting problems which are unrelated to the changes.

File Before After
observabilityDashboards.plugin.js 20.67 MB 20.40 MB
observabilityDashboards.chunk.3.js 5.12 MB 5.25 MB
observabilityDashboards.chunk.4.js 1.77 MB 1.76 MB
Overall 29.18 MB 29.03 MB

Additionally, the incorrect version of @types/react (18) was included in the deps which was corrected in this change.

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@joshuali925 joshuali925 left a comment

Choose a reason for hiding this comment

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

thanks, left a question

@@ -19,7 +19,8 @@ import {
EuiToolTip,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { isEmpty, isEqual } from 'lodash';
import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';
Copy link
Member

Choose a reason for hiding this comment

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

can https://webpack.js.org/configuration/optimization/#optimizationusedexports help to tree shake the

import { isEmpty, isEqual } from 'lodash';

or maybe lodash-es since it's required by core
https://github.com/opensearch-project/OpenSearch-Dashboards/blob/f728b5ae92de732bcf0f491ecf4f90f987291593/yarn.lock#L12596

import { isEmpty, isEqual } from 'lodash-es';

I'm asking because seems devs need to manually type import isEmpty from 'lodash/isEmpty'; as tsserver doesn't suggest default exports. someone using lodash could again introduce import { xxx } from 'lodash'; and bring in the whole library

@joshuali925 joshuali925 merged commit 7a517c9 into opensearch-project:main May 20, 2024
14 of 23 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/dashboards-observability/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/dashboards-observability/backport-2.x
# Create a new branch
git switch --create backport/backport-1828-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 7a517c9fb93418ac1502fd437a58e6294370125c
# Push it to GitHub
git push --set-upstream origin backport/backport-1828-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/dashboards-observability/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-1828-to-2.x.

Swiddis pushed a commit to Swiddis/dashboards-observability that referenced this pull request Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants