fix(storybook): improve speed of storybook plugin #31277
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current Behavior
#22953 updated the way that storybook parsing works to always do full TS tree resolution instead of AST parsing. While this is more accurate, it's orders of magnitude slower...creating a bottleneck in graph creation for larger repos which use the plugin.
The only reason we need to do this complex functionality is to determine if we use angular or not.
Expected Behavior
Graph creation should be quite fast.
This PR returns the old behavior, and uses the new behavior as an additive fallback. In most cases this will result in extremely fast parsing when the framework is defined inline, and in the failure case, it will result in unnoticeably slower parsing as the incremental difference is minor.
Before:
After:
An alternative solve (at least in our case) would be to add an option to skip angular detection...essentially letting people bypass the whole reason for doing this config parsing. Although that's probably not a sustainable option.
NOTE: A majority of the remaining slowness in this plugin is spent hashing the files for the target cache. If we wanted to, we could further speed this up by making some assumptions there...but that may drastically harm repos which rely on the fully resolution behavior
Related Issue(s)
Fixes #31276