Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Proposal: Implement optimizations for JSX, Hooks and Code Splitting #19943

Closed
developit opened this issue Dec 4, 2019 · 6 comments · Fixed by #22253
Closed

Proposal: Implement optimizations for JSX, Hooks and Code Splitting #19943

developit opened this issue Dec 4, 2019 · 6 comments · Fixed by #22253
Assignees
Labels
topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation) topic: webpack/babel Webpack or babel

Comments

@developit
Copy link
Contributor

developit commented Dec 4, 2019

Summary

Over the past few months, we've been working with the Next.js team to implement various transparent optimizations. There are three that seem highly applicable to Gatsby.

The Optimizations

Transparent JSX Optimization

This Babel transform changes JSX output to avoid thousands of JavaScript property accesses in compiled JSX and reduces the impact of JSX on JavaScript parsing time.

Optimize Hook Destructuring
This Babel plugin implements my original recommendation from the V8 team's investigation into the performance impact of Array destructuring in React Hooks. It's transparent to the developer, and has the added benefit of producing significantly less code when Babel is configured in strict mode.

Granular Code Splitting
Gatsby and Next both shared similar SplitChunks configurations up until recently. @atcastle proposed and subsequently landed an implementation of a more granular chunking strategy that has been shown to load less code per-entry for common cases by producing additional shared dependency chunks loaded on-demand.

Motivation

Collectively, bringing these optimizations to Gatsby would represent a nontrivial improvement in output and performance.

Further Optimization

It may also be possible to implement the module/nomodule pattern (#2114) using a Child Compiler technique similar to what @janicklasralph implemented in Next. His work was based on babel-esm-plugin, which I'm working to backport the generalized improvements into. This would enable Gatsby to benefit from @babel/preset-modules, especially true here since Babel is already being used to transform node_modules (yay!).

/cc @wardpeet @spanicker

@wardpeet
Copy link
Contributor

wardpeet commented Dec 4, 2019

Awesome @developit, thanks for opening this issue. The babel plugins should be low effort to implement. Module/no-module was stalled because of our work on gatsby cloud. I'll continue with it after the jobs api, which should be in a week or so.

Nonetheless, other core members could do the babel transformations plugins if they can get to it. The granular chunks we need to check if we can implement it as an experiment or as a plugin for now.

@developit
Copy link
Contributor Author

Sounds good. I like the idea of testing out the new chunking stuff as a plugin.

@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Dec 26, 2019
@LekoArts LekoArts added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Dec 26, 2019
@wardpeet wardpeet self-assigned this Feb 24, 2020
@wardpeet wardpeet reopened this Mar 26, 2020
@wardpeet
Copy link
Contributor

This has only been partially fixed, I still have to add the 2 babel plugins

@moonmeister
Copy link
Contributor

moonmeister commented Apr 7, 2020

In #22253 it was mentioned that react/react-dom were move to a framework package. Does this apply if we're using preact? If not, is this possible?

@moonmeister
Copy link
Contributor

Okay, after some attempts to do this I did manage to get preact working (i think). But It'd be nivce if there was a better way we could use to update the preact plugin.

const FRAMEWORK_BUNDLES = [
  `preact`,
  `react`,
  `react-dom`,
  `scheduler`,
  `prop-types`,
];

exports.onCreateWebpackConfig = ({ stage, getConfig, actions }) => {
  if (stage === "build-javascript") {
    const config = getConfig();

    config.optimization.splitChunks.cacheGroups.framework.test = new RegExp(
      `(?<!node_modules.*)[\\\\/]node_modules[\\\\/](${FRAMEWORK_BUNDLES.join(
        `|`
      )})[\\\\/]`
    );

    actions.replaceWebpackConfig(config);
  }
};

@LekoArts LekoArts added topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation) and removed topic: reach/router and navigation labels May 28, 2021
@gatsbyjs gatsbyjs locked and limited conversation to collaborators Jul 22, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation) topic: webpack/babel Webpack or babel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants