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

Build the frontend by esbuild instead of webpack #1063

Merged
merged 113 commits into from
Jan 25, 2022
Merged

Conversation

baurine
Copy link
Collaborator

@baurine baurine commented Nov 16, 2021

What did:

  • Build the whole frontend by esbuild instead of webpack, and keep the functions and style exact same as before.

Details:

  • Upgrade antd from 4.8 to 4.16 to eliminate tons of compilation errors
  • Upgarde dayjs to dismiss the type check errors
  • Hack the esbuild-plugin-postcss2
    • Fix the bug that can't find .scss files when compiling fluent-ui
    • Fix the bug that can't find bulma/dist/bulma.css
    • Add the cache to reduce incremental build time from more than 4s to near 600ms
    • Log the process time
  • Fix broken styles
  • Fix broken BaseSelect component
  • Fix runtime crash: sentry, formatSQL, path, process.cwd
  • Support diagnoseReport proxy
  • Remove webpack-only methods to handle i18n
  • ...

Result:

Speedup the compilation time nearly by 9x. In a high-performance desktop machine (CPU: Intel Core i5-9400F @ 6x 4.1GHz, Memory: 64GB), the full build costs near 70s by webpack while only near 8s by esbuild, and only near 5s to build js and css.

In the dev mode, after changing js or CSS code, esbuild needs near 600ms to make an incremental build.

production dev incremental
webpack 70.68s fast by hrm
esbuild 7.74s 600ms

Full build time with webpack (1.13 min, aka 67.8s for webpack:build stage):

[09:57:43] Finished 'swagger:generate_client' after 1.51 s
[09:57:43] Finished 'swagger:generate' after 1.82 s
[09:57:43] Starting 'webpack:build'...
[09:58:51] Finished 'webpack:build' after 1.13 min
[09:58:51] Finished 'build' after 1.15 min
Done in 70.68s.

Full build time with esbuild (5.26s for esbuild:build stage):

[22:19:27] Finished 'swagger:generate_client' after 1.58 s
[22:19:27] Finished 'swagger:generate' after 1.9 s
[22:19:27] Starting 'esbuild:build'...
Build started
...
Build ended: 4795ms
[22:19:32] Finished 'esbuild:build' after 5.26 s
[22:19:32] Finished 'build' after 7.16 s
Done in 7.74s.

In dev mode, esbuild cost near 600ms to make incremental build:

Build ended: 4633ms
Serving "build" at http://127.0.0.1:3001
Ready for changes
...
CSS change detected build/dashboard.css
Change detected build/diagnoseReport.css.map
Build ended: 598ms

CI

In CI, the Build UI job cost time is reduced from 2m 8s to 19s.

Demo

Kapture.2021-12-02.at.22.18.40.mp4
Kapture.2021-12-02.at.22.13.52.mp4

Test

Tab 1:

$ tiup playground nightly

You need to install tiup first.

Tab 2:

$ make dev
$ make run

Tab 3:

$ cd ui
$ yarn
$ yarn start

Feedback to upstream

issues or PR reported to upstream:

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 16, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • breeswish

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@baurine baurine marked this pull request as draft November 16, 2021 10:29
@baurine
Copy link
Collaborator Author

baurine commented Nov 16, 2021

  • step 1: compile less/module less/scss
  • step 2: compile antd with customized CSS

image

ui-esbuild/builder.js Outdated Show resolved Hide resolved
@baurine
Copy link
Collaborator Author

baurine commented Nov 16, 2021

  • step3: compile fluentui (need modify esbuild-plugin-postcss2 code)

image

@breezewish
Copy link
Member

Hope we can get this merged before the Spring festival! It would be a giant step.

@@ -129,6 +132,9 @@ function Sider({
// NOTE: Don't remove above comment line, it is a placeholder for code generator
debugSubMenu,
]
if (topSQLSupport) {
menuItems.splice(2, 0, topSQLMenu)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Insert topSQL menu.

@baurine
Copy link
Collaborator Author

baurine commented Jan 21, 2022

hi @YiniXu9506 , can you help have a look why the e2e test always fails, thanks!

@YiniXu9506
Copy link
Contributor

hi @YiniXu9506 , can you help have a look why the e2e test always fails, thanks!

Sure!

@baurine
Copy link
Collaborator Author

baurine commented Jan 24, 2022

All CI jobs are passed, PTAL, @breeswish , thanks!

fail_ci_if_error: true
flags: e2e_test
verbose: true
# - name: Upload coverage to Codecov
Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with this block?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The introduced esbuild causes the plugin in .babelrc does not work. I am working on this.

pkg/apiserver/profiling/model.go Outdated Show resolved Hide resolved
pkg/apiserver/profiling/service.go Outdated Show resolved Hide resolved
ui/.env.production Show resolved Hide resolved
@@ -19,6 +19,10 @@
display: flex;
flex-direction: column;
padding-bottom: 20px;

.ant-menu.ant-menu-inline-collapsed {
width: @menu-collapsed-width; // 80px
Copy link
Member

Choose a reason for hiding this comment

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

Is this an ant-design bug? If so, maybe you'd better propose a minimal reproducible example and file an issue.

// return mySqlFormatter.format(sql || '')
// }

import { format } from 'sql-formatter'
Copy link
Member

@breezewish breezewish Jan 24, 2022

Choose a reason for hiding this comment

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

What's the impact of not using a TiDB SQL formatter? I believe something may get wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will crash when using the forked formatter, and the upstream still keep updated.

image

Copy link
Member

Choose a reason for hiding this comment

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

But as we are specially introducing a TiDB formatter, will there be any feature breaks when it is not used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did some manual tests, it looks the same as before, but I'm not 100% confident, I think we should add some unit tests for this method, I will book a todo.

])

// fetch data when instance id / time window size update
useEffect(() => {
handleUpdateTopSQLData()
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Member

Choose a reason for hiding this comment

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

Do we have some safer way to do this magic? I mean, something that will not be reported by the lint while simple enough. I'm not an expert of React hook. How does other React hook users deal with this kind of case? @shhdgit

Copy link
Member

Choose a reason for hiding this comment

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

OK, this is not a good scenario for the use of side effects. According to this article: https://stackoverflow.com/questions/58866796/understanding-the-react-hooks-exhaustive-deps-lint-rule

In the similar case, I should call the function directly when the event is triggered. Oh my react.

ui/lib/apps/KeyViz/components/KeyViz.tsx Outdated Show resolved Hide resolved
ui/lib/apps/KeyViz/heatmap/index.tsx Outdated Show resolved Hide resolved
ui/gulpfile.esm.js Show resolved Hide resolved
@ti-chi-bot ti-chi-bot requested a review from YiniXu9506 January 25, 2022 00:44
Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

The rest LGTM. I think we can fix trivial issues after the PR is merged.

@baurine baurine merged commit db6fb66 into pingcap:master Jan 25, 2022
shhdgit added a commit to shhdgit/tidb-dashboard that referenced this pull request Mar 16, 2022
@shhdgit shhdgit mentioned this pull request Mar 16, 2022
shhdgit added a commit to shhdgit/tidb-dashboard that referenced this pull request Mar 16, 2022
@baurine baurine deleted the esbuild branch April 15, 2022 08:37
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.

6 participants