-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Starting storybook takes very long #3968
Comments
You can probably add a profile prop in the custom Also, can you share it? |
Unfortunately, it's not a public project. I've started to generate some webpack stats files and playing around with different webpack configurations. Webpack compiler configuration
So, somehow parallelism runs faster at 1 compared to any other input value (tested 2 as well) Story-LoaderI also noticed that the compiler always stops right after
Which is triggered by this I guess?
Loading just 1 story was quite interesting
I forced to just require 1 single story but the compiler stucks again right at the first story he tries to pack
It seems it has nothing to do with how many stories I have but with webpack starting to pack the first story. After that it does not stop again. Is this in any way helpful? I can try to isolate this in a fresh Angular-CLI 6.1 Project with webpack.config.ts
config.js
|
Very nice research. |
It isn't configured (thanks for the hint) because it does not fit to our way of writing stories in angular (see #3566 (comment)) I tried to deactivate all addons and stopped loading Nothing improved the build time |
Which tsconfig is used to build storybook? The root tsconfig of a project? |
Storybook itself is not in TS. For angular you have this - https://github.com/storybooks/storybook/blob/master/app/angular/tsconfig.json |
Thanks! I found out that I can place a custom tsconfig in the .storybook configuration folder I tried to start with an empty project and add more and more stuff but this does not produce this issue. I'm now going the other way around and remove more and more stuff from our project until the issue is gone. Hopefuly, the result of my work makes it possible to offer you a github repo or at least a way to reproduce this. Super cool would be some sort of parameter in the CLI to analyze the webpack build I assume using https://github.com/stephencookdev/speed-measure-webpack-plugin/ is only possible in full-control mode without extending the storybook base config? Is this even possible in an angular project with angular-cli? |
Not sure, I got you what it will do
Yeah, you can add whatever you want to webpack in the extended/full control of any app |
@kroeder @igor-dv I also faced with significant performance issues during starting up storybook. It works fast in case of having one or two simple stories, but adding about 10 leads to start up time about 3-4 mins. |
Can you reproduce this in a Repo? I was not able to.. |
Yes, sure. You can open browser console for this page https://storybooks-angular.netlify.com/?selectedKind=Addon%7CKnobs&selectedStory=All%20knobs&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybooks%2Fstorybook-addon-knobs&background=%2300aced |
I didn't find such behavior for stories which doesn't have knobs |
Probably performance issue is related somehow to typescript files processing. https://storybook.js.org/configurations/typescript-config/ |
If awesome-typescript-loader solves the performance, we can make it work, Storybook doesn't use angular-cli's |
So could you please explain how angular-cli example is working without any typescript configuration? Does default webpack config contain typescript loader definition? |
I did some more research regarding my initial issue I said "Loading 1 story takes as long as loading every story (about 40-45)" Loading 1 story in a project with 40-45 stories takes as long as loading every of these 40-45 storiesNote that these times were recorded on a different machine than the one I used for my research above Start time: 1,5min
Removing every component + story except 1Start time: 0,5min I prepared a repo with the 1 story scenario but I guess this is of no interest if it runs so much faster than one with many components, which I can't make public.. In my next steps I'll play around with a seperat tsconfig file for storybook. It seems that starting storybook includes every file that is specified in the root tsconfig.json. I noticed that by removing all of the components. Compile errors occurred in non-story relevant code Edit: Might work if I add 40 dummy stories |
@kroeder, it makes sense the problem is somewhere in ts configuration. Maybe you can just copy-past an existing component 100 times to simulate the problem ? @andrei-ilyukovich with the full control mode of the webpack.config, you can do something like this (pseudo): module.exports = (basicConfig, mode, defaultConfig) => {
basicConfig.module.rule = removeTsRule(basicConfig.module.rule);
basicConfig.module.rule.push(createAwesomeTsRule())
return basicConfig;
}; |
@kroeder @igor-dv It look like I found solution to reduce building time significantly. The reason why it takes so long in current config is just ts-loader configuration, which is used internally by storybook. We need to skip type checking with setting flag const path = require("path");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
module.exports = (baseConfig, env, config) => {
// Find rule for processing ts files and then add transpileOnly option to skip type checking
let rule = config.module.rules.find((rule) => rule.use[0].loader.includes("ts-loader"));
rule.use[0].options.transpileOnly = true;
// Add plugin to have separate type checking
config.plugins.push(
new ForkTsCheckerWebpackPlugin({
tslint: path.resolve(__dirname, "../tslint.json"),
tsconfig: path.resolve(__dirname, "tsconfig.json")
})
);
return config;
}; Another option is to replace ts-loader with awesome-typescript-loader. With such config build time is about 25 sec, which is good but worse than first solution. const path = require("path");
module.exports = (baseConfig, env, config) => {
// Find rule for processing ts files and then set new loader
let rule = config.module.rules.find((rule) => rule.use[0].loader.includes("ts-loader"));
rule.use[0].loader = require.resolve("awesome-typescript-loader");
// "awesome-typescript-loader" has a bit different option name to set tsconfig.json (ts-loader has configFile option)
rule.use[0].options.configFileName = path.resolve(__dirname, "tsconfig.json");
return config;
}; |
😱 omg, it's a huge difference. We probably need to enable BTW, there is an option to define a custom tsconfig.json in the .storybook dir. |
Basically tslint is just an option, you could configure ForkTsCheckerWebpackPlugin to not make ts linting. Yes, I know about custom tsconfig.json, in examples above I have to set it explicitly, because by default it isn't picked up by plugin |
Can confirm. Without Might be quicker but I have do deal with a couple new typescript errors like
or
|
After fixing everything it takes around 30-35s - Sadly, my hot-reload still takes around 5s but that's ok for now More good news: It seems this approach moves the build-time bottleneck somewhere else. Before: Sorry for throwing around with numbers the whole time but I guess build time is exactly about that 😃 So: @igor-dv is this something you would consider add to the Maybe too naive? |
I think we need to include Would somebody like to PR this? |
What about your concerns regarding
|
Makes sense |
On the other hand: nowadays you might use storybook in Angular 6 library projects which have multiple projects / tslint.json Per default, angular-cli creates a library project with its own tslint.json containing
File-structure
I haven't seen support for this in Fork TS Checker Webpack Plugin (and hardly can imagine how this should work). Only one tslint can be used Has the old E.g.
Not defining Not sure if it does not includes any linting, though. Must be tested My proposal would be:
Update: ForkTsChecker does work without |
Hi everyone, I'm using @Storybook/react 4.1.6 with the recommended config in the Storybook docs:
It currently takes 4 minutes for Storybook to compile and start. I've tried to implement the examples mentioned above to resolve this however I keep getting errors such as:
Any idea how I can speed up my start time whilst also using Thanks |
@nicholasmaddren Did you find any performance optimisations? |
@igor-dv @ndelangen do you know anything about that issue? |
@kroeder I had the same problem. Removing |
If you haven't already, it's worth ensuring you've provided an explicit
This took my generation down from 2 minutes to 9 seconds. Without the |
I've observed that babel-loader for me starts up a lot faster than atl - maybe it would make sense to change that in the sb documentation? |
I'm having a similar issue where starting SB pretty consistently takes about 10 minutes. It will be going fine and then it hangs on some arbitrary file (it's a different file every time) and then it finishes out fine. Meaning it only hangs once but it takes 10 minutes. I'm on Storybook 5, but I'm not using TypeScript. It was working fine with a few simple components but there are a couple of components I added that are now causing it to hang. The components in question work fine in production. |
@flxwu Mind submitting a PR for a docs change? |
@maninacan Wanna jump on our discord? Maybe somebody from the community can help you debug it? https://discordapp.com/invite/UUt2PJb |
This is really annoying and frustrating, and this is still happening to me!
If I comment this line, it works fast and well. If I uncomment it, it stops at around 36%. Edited: |
Hey I might have found something here! I wanted storybook to load all files in any
This was making the start up time to take minutes (I think, I never waited it to end, actually).
I'm not sure what was really causing it, but storybook could be doing some kind of deadlock there, or some level of loop. I hope this might help someone who faces the same situation. |
Interesting @felipenmoura . So the idea is that when you have multiple globs that resolve to the same story, some race condition is triggered that blows up the startup time? |
I'm hoping that in the future, we don't rely on webpack's require.context at all anymore, and we resolve the globs (and can de-dup them) in node before starting webpack. Sounds that might resolve that issue @shilman ? |
@ndelangen that it would. it might also help with #12771 ? |
yup, exactly @shilman , this is not a critical problem, but it took me quite a while to figure it out :p |
Oh my...we are facing this problem all over again! |
Bug or support request summary
I'm not sure if this is just the nature of a big storybook (we got 46 stories so far 😃 ) but starting it takes more and more time (about 2,5 min, currently)
Also hot-reloading takes about 3-5s (which is "fine" but not smooth compared to the initial experience of an empty project)
I'd like to investigate this further and, if possible, improve this but I don't really know where to start.
One thing I already noticed is, that the build stops at a certain % for quite a while; it takes about 60-70% of the whole build time
First try
Second try
Third try
Have you noticed this yourself for larger storybook projects?
Do you know any tools or options I can use to identify the root of this problem?
We are getting about 10-15 more stories the next couple months I guess. I hope at least the hot reload time does not scale further with the size of our project
Please specify which version of Storybook and optionally any affected addons that you're running
The text was updated successfully, but these errors were encountered: