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

Performance optimizations on separate manager preview split, improved cold start, restart & rebuild #4834

Merged
merged 29 commits into from Nov 30, 2018

Conversation

ndelangen
Copy link
Member

This PR adds optimisation to the preview-manager split.

It uses a couple of techniques to make the cold start and hot restart of webpack faster.

I've done some testing and the performance of the manager seems heavily dependent on how busy the preview is...

I think this means it WOULD be logical to move the manager back out into it's own process.

Overall I'm seeing a 41s start-up on the next branch, this one has a bit more reasonable time of 11s.

When I stop and re-start the dev server I'm seeing a boot up time of 9 seconds.


I also added a bunch of logs and profile data from webpack to be able to somewhat debug what is happening.

The total time for manager and preview are now printed in the terminal for end-users. They'll be more incentivised to report issues I hope, or at the very least they'll get feedback if performance is improving or deteriorating.


  • One of the techniques is a shared cache between the 2 instances of webpack
  • One is using a DLL plugin for the entire lib/ui
  • One is to resolve the configs in parallel

The debug info is written to the cache dir when you perform a smoke-test.

The debug information includes all the stats for both manager and preview. You can dump them into something like:
https://chrisbateman.github.io/webpack-visualizer/ or http://webpack.github.io/analyse/#modules

The lib/ui will be missing because it's essentially pre-bundled.

Another piece of debugging data is the full event log of webpack.
Maybe it's a bug, maybe I'm doing something wrong, but it seems to be the combined log of both webpack instances. either way it can be insightful what is taking webpack so long.

@ndelangen ndelangen self-assigned this Nov 22, 2018
@ndelangen ndelangen added this to the next milestone Nov 22, 2018
@ndelangen ndelangen force-pushed the separate-manager-preview-p5 branch 2 times, most recently from e79d295 to 84962d9 Compare November 23, 2018 12:35
@codecov
Copy link

codecov bot commented Nov 23, 2018

Codecov Report

Merging #4834 into next will decrease coverage by 0.37%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #4834      +/-   ##
==========================================
- Coverage   35.21%   34.84%   -0.38%     
==========================================
  Files         564      566       +2     
  Lines        6931     7005      +74     
  Branches      931      937       +6     
==========================================
  Hits         2441     2441              
- Misses       3996     4064      +68     
- Partials      494      500       +6
Impacted Files Coverage Δ
lib/ui/src/modules/api/configs/init_api.js 79.16% <ø> (ø) ⬆️
lib/core/src/client/preview/story_store.js 94.11% <ø> (ø) ⬆️
...b/core/src/server/preview/iframe-webpack.config.js 0% <ø> (ø) ⬆️
.../ui/src/modules/ui/components/menu_item.stories.js 100% <ø> (ø) ⬆️
...onents/stories_panel/stories_tree/index.stories.js 94.44% <ø> (ø) ⬆️
...ui/src/modules/ui/components/search_box.stories.js 60% <ø> (ø) ⬆️
...ui/components/stories_panel/text_filter.stories.js 100% <ø> (ø) ⬆️
...rc/modules/ui/components/shortcuts_help.stories.js 57.14% <ø> (ø) ⬆️
...dules/ui/components/stories_panel/index.stories.js 91.66% <ø> (ø) ⬆️
lib/core/src/server/build-dev.js 0% <0%> (ø) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b224a2...67d2629. Read the comment docs.

Changelog formatting

Bump @storybook/addon-actions from 4.0.0 to 4.0.8 in /docs

Bumps [@storybook/addon-actions](https://github.com/storybooks/storybook) from 4.0.0 to 4.0.8.
- [Release notes](https://github.com/storybooks/storybook/releases)
- [Changelog](https://github.com/storybooks/storybook/blob/next/CHANGELOG.md)
- [Commits](v4.0.0...v4.0.8)

Signed-off-by: dependabot[bot] <support@dependabot.com>

update `npm install` to match current requirements

Add TypeScript support for react-scripts

4.1.0-alpha.5 changelog

v4.1.0-alpha.5

4.1.0-alpha.6 changelog

v4.1.0-alpha.6

Reduce jest image size

4.1.0-alpha.7 changelog

v4.1.0-alpha.7

ADD webpack stats generation for debugging

Revert "Update LICENSE"

This reverts commit 69fc051.

Don't change rootElement when received node is the same

Merge pull request #4830 from aliceyoung9/patch-1

little documentation fix

FIX linting
@ndelangen ndelangen added the maintenance User-facing maintenance tasks label Nov 23, 2018
# Conflicts:
#	addons/backgrounds/package.json
#	lib/ui/package.json
@ndelangen ndelangen changed the title WIP Separate manager preview p5 Performance optimizations on separate manager preview split, improved cold start, restart & rebuild Nov 26, 2018
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { shippedProposals: true, modules: false }],
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like i've seen this above. Maybe the babel rcs could be moved to a common location?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like an improvement/refactor we could do a bit later. Good suggestion!

@tmeasday
Copy link
Member

tmeasday commented Nov 28, 2018

@norbert - re the Chromatic failures -- looking at a saved snapshot in liveview, e.g. https://www.chromaticqa.com/component?appId=5a375b97f4b14f0020b0cda3&name=App%7Cacceptance&specNumber=1&buildNumber=5357

It looks to me like the project hasn't build properly, specifically this file: https://xxzvtulteo.tunnel.chromaticqa.com/sb_dll/storybook_ui_dll.js

Which serves:

Error: ENOENT: no such file or directory, stat '/mnt/agent/work/a1796458d49a7849/lib/core/dist/public/sb_dll/storybook_ui_dll.js'

(those directories [/mnt/agent/...] are on teamcity's side I think)

@ndelangen
Copy link
Member Author

Who can give this a final check, so we can move ahead and merge. That way we can get this in a "next" release?

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

Code LGTM.

I compared it to next on my iMac:

On next:

╭──────────────────────────────────────────────────╮
│                                                  │
│   Storybook 4.1.0-alpha.8 started                │
│   26 s for manager and 12 s for preview          │
│                                                  │
│   Local:            http://localhost:9011/       │
│   On your network:  http://192.168.0.22:9011/    │
│                                                  │
╰──────────────────────────────────────────────────╯

On this branch:

╭──────────────────────────────────────────────────╮
│                                                  │
│   Storybook 4.1.0-alpha.8 started                │
│   7.46 s for manager and 9.1 s for preview       │
│                                                  │
│   Local:            http://localhost:9011/       │
│   On your network:  http://192.168.0.22:9011/    │
│                                                  │
╰──────────────────────────────────────────────────╯

Seems positive.

It did output this:

Error: ENOENT: no such file or directory, stat '/Users/tom/OSS/storybook/lib/core/dist/public/runtime~main.3aaa912fd37e258bb4b5.bundle.js'
Error: ENOENT: no such file or directory, stat '/Users/tom/OSS/storybook/lib/core/dist/public/main.ef442cdddb07ad8080c3.bundle.js'
Error: ENOENT: no such file or directory, stat '/Users/tom/OSS/storybook/lib/core/dist/public/vendors~main.9171936130daf921c71d.bundle.js'
Error: ENOENT: no such file or directory, stat '/Users/tom/OSS/storybook/lib/core/dist/public/runtime~main.0f4ed394e749803fae17.bundle.js'
Error: ENOENT: no such file or directory, stat '/Users/tom/OSS/storybook/lib/core/dist/public/main.0f4ed394e749803fae17.bundle.js'
Error: ENOENT: no such file or directory, stat '/Users/tom/OSS/storybook/lib/core/dist/public/vendors~main.0f4ed394e749803fae17.bundle.js'

It didn't seem to cause any issues though, and didn't appear on a second run.

Copy link
Member

@igor-dv igor-dv left a comment

Choose a reason for hiding this comment

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

Shouldn't we "watch" on dlls?

One of the techniques is a shared cache between the 2 instances of webpack

If manager will be moved to its own process, this option probably can't be used. Also, can't this cache become problematic with manager and preview having a different react versions?

lib/core/src/server/build-dev.js Outdated Show resolved Hide resolved
lib/core/src/server/build-static.js Outdated Show resolved Hide resolved
lib/core/src/server/build-static.js Outdated Show resolved Hide resolved
lib/core/src/server/build-static.js Outdated Show resolved Hide resolved
lib/core/src/server/manager/manager-webpack.config.js Outdated Show resolved Hide resolved
lib/ui/package.json Outdated Show resolved Hide resolved
lib/ui/scripts/config.js Outdated Show resolved Hide resolved
lib/ui/scripts/script.js Outdated Show resolved Hide resolved
@@ -1,6 +1,6 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { storiesOf } from '@storybook/react'; // eslint-disable-line import/no-extraneous-dependencies
Copy link
Member

Choose a reason for hiding this comment

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

what happened in all these files?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to remove the cyclical dependencies warnings from lerna

package.json Show resolved Hide resolved
@ndelangen
Copy link
Member Author

Some debugging to do:

Summary of all failing tests
 FAIL  examples/cra-kitchen-sink/src/storyshots.test.js
  ● Test suite failed to run

    Cannot find module 'App' from 'App.stories.js'

      7 | storiesOf('App', module).add('full app', () => <App />);
      8 |

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (examples/cra-kitchen-sink/src/stories/App.stories.js:9:35)

 FAIL  examples/angular-cli/angularshots.test.js
  ● Test suite failed to run

    Cannot find module '/Users/dev/Projects/GitHub/storybook/core/examples/angular-cli/.storybook/config' from 'configure.js'

      36 |   const resolvedConfigPath = getConfigPathParts(configPath);
      37 |
    > 38 |   require.requireActual(resolvedConfigPath);
         |           ^
      39 | }
      40 |
      41 | var _default = configure;

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at configure (addons/storyshots/storyshots-core/dist/frameworks/configure.js:38:11)
      at Object.load (addons/storyshots/storyshots-core/dist/frameworks/angular/loader.js:36:26)
      at loadFramework (addons/storyshots/storyshots-core/dist/frameworks/frameworkLoader.js:32:17)
      at testStorySnapshots (addons/storyshots/storyshots-core/dist/api/index.js:47:36)
      at Object.<anonymous> (examples/angular-cli/angularshots.test.js:22:30)


Test Suites: 2 failed, 112 passed, 114 total

@ndelangen ndelangen dismissed igor-dv’s stale review November 30, 2018 12:36

Got confirmation on discord that this is approved

@ndelangen ndelangen merged commit 5f69057 into next Nov 30, 2018
@ndelangen ndelangen deleted the separate-manager-preview-p5 branch November 30, 2018 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core maintenance User-facing maintenance tasks performance issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants