-
Notifications
You must be signed in to change notification settings - Fork 63
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
More lazy loading of react components to reduce bundle size #1888
Conversation
sv inspector needs a fix to use LazyReactComponent so that's on the todo, note still draft PR |
MB size calculated by filtering on /.js$/ in the network tab in chrome |
Some new figures made by kicking some of the widget code into lazy loading
|
Codecov Report
@@ Coverage Diff @@
## main #1888 +/- ##
==========================================
- Coverage 58.13% 57.59% -0.54%
==========================================
Files 461 458 -3
Lines 21488 21342 -146
Branches 5102 5094 -8
==========================================
- Hits 12491 12291 -200
- Misses 8686 8741 +55
+ Partials 311 310 -1
Continue to review full report at Codecov.
|
Appears to need fixing for plugin builds, tried adding inlineDynamicImports to the packages/development-tools rollup config but not there yet. That does imply plugin builds wouldn't use code splitting Also there is an alt branch that extends this PR by making data adapters import their parsers on the fly too That makes it so that for example you don't import the @gmod/bam until you actually load a BAM track (The BamAdapter is actually still loaded, but the @gmod/bam is delayed...there may be another way to approach that too that doesn't require so much digging into the data adapters where the adapter itself is lazily loaded) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had a chance to go through this thoroughly yet, but see a couple initial comments. Also a couple questions:
- If e.g. a widget's ReactComponent is not lazy, will the Suspense handle that ok?
- Does this mean that any product that uses e.g. a plugin with a ViewType will need to wrap the ReactComponent in a Suspense? Can we make TypeScript aware of that by e.g. using
LazyExoticComponent
in theViewType.ts
base class?
...cts/jbrowse-react-linear-genome-view/src/JBrowseLinearGenomeView/JBrowseLinearGenomeView.tsx
Outdated
Show resolved
Hide resolved
yes, the Suspense is pretty flexible, see here https://reactjs.org/docs/code-splitting.html (specifically how normal jsx, and several lazy components are in that one example)
I think that is a good idea, testing it out now... |
…ExoticComponent wrappers to View/Widget types
Ended up needing, at least from cursory look, LazyExoticComponent<React.FC<...>>|React.FC<...> to properly type it being lazy or not |
…->stateModel which triggers the no pluggable elements found in tests that dont register a view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few little nits to pick, comments and questions, but ok to merge as is.
@@ -0,0 +1 @@ | |||
declare module '@jbrowse/core/ui/RecentSessionCard' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved packages/core/ui/StartScreen.tsx to products/jbrowse-desktop/src/StartScreen.tsx and correspondingly needed to move a declare.d.ts for this item there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because jbrowse-web already had it's own specialized StartScreen so I figured there was no need to have one in core
Currently loading the page load
This PR does not help too much yet but I thought some more work to reduce JS size could be beneficial
Note that the lazy loading isn't paying off big yet but I think it could help in the long run cut our load times
Current payloads with this PR