Skip to content

ReactInitJavaScript performance issues #821

@vezaynk

Description

@vezaynk

Please verify these steps before filing an issue, and check them off as you go

  • The relevant native JavascriptEngineSwitcher library packages are installed (such as JavaScriptEngineSwitcher.V8.Native.win-x64)
  • The VC++ 2017 runtime is installed (I'm not sure, running under Linux)
  • The value of SetUseReact and SetUseBabel is correct in ReactConfig.cs or Startup.cs
  • I've looked at the sample projects in this repo to verify that my app is configured correctly

I'm using these library versions:

All the latest and greatest things. (Recently updated all packages)

  • node: Is node a dependency? Isn't ChakraCore what executes the JS?

Runtime environment:

  • OS: (Mac, Windows, Linux flavor. Include 32-bit/64-bit and version): Arch Linux 64 bit
  • .NET Framework or .NET Core Version: dotnet core 2.2.105

Steps to reproduce

I don't have a minimal reproducible example, I'm unsure if it is necessary as trying to build one will likely be a pain and the issue itself is probably straight-forward.

I outline the issue with some rough numbers here.

Long story short, calling @Html.ReactInitJavaScript() causes a significant performance burden even if there are no React components on the page. This is likely due to the fact that my JavaScript bundle is pretty big, and even node takes a while to go through it:

$ time node wwwroot/js/server.js
node wwwroot/js/server.js  0.45s user 0.04s system 105% cpu 0.461 total

My guess is that calling ReactInitJavaScript() causes the bundle to be loaded even if it is not necessary which raises two issues for me:

  1. Imho, the bundle should not be loaded if there are no components to hydrate (Having client-only components on the page still does not require the server to load the bundle on its end).

  2. I don't see why the bundle needs to be loaded on every page load. Would it possible to load it once, precompile it and then use the precompiled javascript for each pageload instead of redoing it every time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions