Frank
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Scalability for Storybook In this post, we will discuss the notion of scalability concerning the StoryBook project. As scalability is an aspect where software architecture plays a particularly important role, this had to be analyzed in our series of posts about the project. ## Scalability challenges Fortunately for the Storybook project, most known scalability challenges do not apply to it. Examples of these challenges are database scaling and insufficient caching [^sean-hull]. Storybook is used locally on the machine of the developer, where each developer has his own copy of Storybook as a **node module dependency**. This means that Storybook is inherently centralized for each user that installs the package. Being a **single package**, Storybook does not have to deal with scalability patterns such as Scatter/Gather or Master/Architecture [^lecture]. Moreover, it does not have to deal with multiple users at runtime (for distribution this is different, but this is taken care of by the NPM registry). Workload and load balancing also do not apply as scalability challenges [^npm-distribute]. What could be a scalability issue for Storybook, is the amount of **component dependencies**. Storybook builds upon several other packages such as Babel, TypeScript, and webpack. Storybook uses node modules as the architectural pattern for managing their dependencies. This is mainly done in the package.json file [^package] where the dependencies are listed and the required versions (or even range of versions) are specified. This facilitates scalability as the NPM registry will provide the packages needed and Storybook does not have to keep track or worry about having or distributing the correct dependencies. This allows for flexibility as the system's components are loosely coupled and can be reconfigured at any time. However, when working with multiple add-ons or non-trivial frameworks Storybook can face the issue of conflicting dependency requirements. The developers of Storybook are aware of this and this is on the current roadmap [^roadmap]. Nevertheless, there are a couple of key scalability challenges certainly applicable to the project. As the tool is often used for projects that could be maintained by a large team of developers, it can be difficult to work together using Storybook. Storybook is a separate interface and although **collaboration** is certainly possible using Git, the Storybook interface and personal workflow make collaborative development more difficult. Furthermore, when having a **large amount of *stories* with multiple states**, having a clear overview of all components is difficult. Components can become complex with a large number of states and arguments. Although this is inherently an issue for projects getting more complex and bigger, Storybook is affected by this as this pollutes the developer UI of Storybook. ## Scalability Analysis There exists a variety of scaling dimensions, such as the number of clients, input size, state size, etc. Each of these dimensions can be analyzed to find the bottlenecks of a system's scalability potential. As Storybook is a dependency, where the dependency management is handled by NPM, many of these scaling dimensions do not apply to the project. For our analysis, we decided to analyze the **startup time** for the Storybook interface, given a certain project. Performance is key for scalability [^sean-hull], and we experienced that this loading time degrades the usability for UI developers. For our analysis, we have compared two projects which made use of Storybook to develop components. We measured the time difference for the Storybook interface to initialize between both these projects, see Table 1. | Application | Time | |-----------------------------------------------------------------------------------------------------------------------|------------| | A basic React application using a few simple components, as can be installed from the StoryBook documentation [^docs] | 13 seconds | | The MetaMask project [^metamask] | 97 seconds | **Table 1:** Startup time Furthermore, we tested adding add-ons to the starter project to analyze whether this affects the loading time. It is common that when a Storybook project grows, more add-ons are added. We measured the time difference with regards to initialization duration for the basic React application given the number of add-ons, see Table 2. As a side note, these are the most used Storybook add-ons [^addon-catalog]. | Application | Time | |----------------------------------------------------------|------------| | Bare application [^docs] | 13 seconds | | Accessibility addon [^ally] added | 15 seconds | | Links addon [^links] and designs addon [^designs] added | 17 seconds | **Table 2:** Startup times with addons As can be observed, we noticed that Storybook scales quite well with adding plugins. However, component size does influence the loading time quite substantially. Notwithstanding, the Storybook contributors are aware of this fact, and they are working on it [^on-demand]. ## Architectural decisions for scalability Naturally, scalability is an important aspect of development. To make an application scale well, many architectural decisions must be made throughout the development of the project. In this section, we will discuss these decisions, as well as some recent changes to the architecture of Storybook that will improve their scalability. Finally, we will discuss some parts of Storybook that could still benefit from improvements. Let's start with some of the decisions that truly define Storybook as a scalable product. ### Addons One of the key features of Storybook is its **extendability** through its capability to plugin addons for extra features. These addons can do many interesting things, ranging from dark mode to source code generation. By separating these addons from the main project, Storybook can focus on developing only core functionalities. On the development side, this allows Storybook to scale, without adding a lot of dead weight in dependency sizes to the user's projects. ### Separated framework code Storybook supports, as of speaking, 8 different frameworks. All of these frameworks need their own framework-dependent code to function. However, a lot of code can also be shared between the frameworks. Therefore, Storybook has made sure to clearly define the core of the project, which is shared amongst all the framework-specific projects. This, again, reduces dead code and code duplication in the user's projects. ### Code Splitting We also need to talk about the major overhaul that Storybook introduced in the past year to one of its most important bottlenecks: **bundling and building the stories and components**. Previously, the way Storybook went about this process was simple: Just build and bundle all stories, components, and their dependencies into one big bundle, as depicted in **Figure 1**. ![](https://i.imgur.com/tWHCEGx.png) **Figure 1:** How stories and components were bundled previously But when it comes to the performance of bundling and building, smaller *equals* better[^smaller-better]. Minimizing large bundles is called code splitting. The primary purpose of introducing code splitting is to improve the performance of your Storybook. That is, the time it takes to install and startup and how long it takes to download and interact with a built Storybook. Because of this, the team behind Storybook focused on enabling code splitting in Storybook for version 6.4 of Storybook[^sb-v6.4]. The immediate impact is smaller bundle sizes, which means that built Storybooks should load up faster. This allows for larger Storybooks without losing performance. We can see the resulting bundles when building with these changes in **Figure 2**. ![](https://i.imgur.com/2stLwvp.png) **Figure 2:** How stories and components are bundled with StoryStore V7 After these changes, Storybook has seen both build sizes and times to render the first story improve drastically, as can be seen in **Table 2**. | Chromatic Benchmark Results | Spotify Benchmark Results | |:------------------------------------:|:------------------------------------:| | ![](https://i.imgur.com/bhCL2OP.png) | ![](https://i.imgur.com/VBLfxHF.png) | **Table 3:** Results from benchmarks with the new changes[^results-on-demand]. There is a major caveat to the change mentioned above: *The bundles are still loaded at the same time.* Therefore, even if the bundles are faster to build as a whole, a lot of improvement can still be found, because not all bundles are needed at the start. ## Our proposed optimizations To build further on the performance changes that we mentioned above, and that was realized in 6.4[^sb-v6.4], we propose that Storybook makes use of a new feature that became available in Webpack 5: **lazy compilation**[^webpack-5]. This will allow Storybook to only generate the bundles required to render the stories currently visible on the screen. With this change, a storybook should be able to render much more quickly and be able to handle many more stories without also requiring much more memory and much longer build times. Another feature of Webpack 5 that would work in tandem with lazy compilation is **(file system) caching**[^webpack-5]. Using this feature, webpack would cache previous builds (or parts of it) and skip the no longer necessary steps when rebuilding, using this cache. This might come at a detriment to memory usage (either RAM or Disk), and therefore it requires experimentation to find a good trade-off. In **Figure 3** we have depicted the way Storybook would work with our changes. When a user requests to see the *button story*, the *Story store* would go ahead and only bundle that story file. After switching the screens, the *Story store* would then cache the previous story file, to reduce the following build-time when the user requests the *SettingsScreen* stories again. ![](https://i.imgur.com/5YX1taU.png) **Figure 3:** Our proposed Storybook optimizations ## Optimizations in practice We will now conduct a brief empirical quantitative analysis to show how **lazy compilation** and **file system caching** reduce loading times. According to the blog written by the maintainers of the project, it should decrease the time by a factor of 3-5x. The difference in loading times between a simple React application using Storybook, and the larger MetaMask project, are displayed in Table 4. | Application | Start time w/o optimization | Start time with optimization | | ---------- | ---------------------- | ----------- | | A basic React application using a few simple components, as can be installed from the StoryBook documentation [^docs] | 13 sec | 9.15 sec | | The MetaMask project [^metamask] | 97 sec | 57 sec | **Table 4:** Loading times As can be seen in Table 4, both the start time and the rebuild time are significantly improved by these optimization changes. We believe that these changes are essential in scaling and using StoryBook with larger projects. [^sean-hull]: https://queue.acm.org/detail.cfm?id=2512489 [^metamask]: https://github.com/MetaMask/metamask-extension [^docs]: https://storybook.js.org/docs/react/get-started/install [^ally]: https://storybook.js.org/addons/@storybook/addon-a11y/ [^links]: https://storybook.js.org/addons/@storybook/addon-links/ [^designs]: https://storybook.js.org/addons/storybook-addon-designs/ [^addon-catalog]: https://storybook.js.org/addons [^on-demand]: https://storybook.js.org/docs/react/configure/overview#on-demand-story-loading [^roadmap]: https://storybook.js.org/blog/state-of-storybook-2021/ [^npm-distribute]: https://storybook.js.org/docs/react/get-started/install [^package]: https://github.com/storybookjs/storybook/blob/next/package.json [^lecture]: https://se.ewi.tudelft.nl/delftswa/2022/slides/lecture4-architecting-for-scale.pdf [^smaller-better]: https://webpack.js.org/guides/build-performance/#smaller--faster [^results-on-demand]: https://storybook.js.org/blog/storybook-on-demand-architecture/ [^sb-v6.4]: https://storybook.js.org/blog/state-of-storybook-2021/ [^webpack-5]: https://webpack.js.org/blog/2020-10-10-webpack-5-release/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully