-
Notifications
You must be signed in to change notification settings - Fork 687
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
[feature]: Lazy Load/trim unused bytes in main routes #2988
[feature]: Lazy Load/trim unused bytes in main routes #2988
Conversation
Signed-off-by: sirugh <rugh@adobe.com>
Signed-off-by: sirugh <rugh@adobe.com>
@@ -33,7 +33,6 @@ services: | |||
- ./packages/venia-concept/static:/usr/src/app/packages/venia-concept/static:rw | |||
- ./packages/venia-ui/.storybook:/usr/src/app/packages/venia-ui/.storybook:rw | |||
- ./packages/venia-ui/lib:/usr/src/app/packages/venia-ui/lib:rw | |||
- ./packages/venia-ui/templates:/usr/src/app/packages/venia-ui/templates:rw |
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.
For starters, I might have scope creeped this a bit but as far as I can tell we no longer use the templates
, opting instead to use venia-concept/template.html
. @zetlen @revanth0212 can ya'll confirm this?
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.
You are right. We got rid of mustache templates in favor of Webpack's HTML Plugin which utilized template.html to render the main HTML file.
|
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.
Makes sense to me. Good savings. 👍
Signed-off-by: sirugh <rugh@adobe.com>
<() => { | ||
/* istanbul ignore next */ | ||
cov_101e9trynu().f[0]++; | ||
cov_101e9trynu().s[1]++; |
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 don't know why code coverage started showing up in some of the snapshots but not others. It has something to do with the jest mock. When the mock is local to the component being tested the coverage comments do not appear.
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.
ok it looks like this was happening because I was running with some jest filter like "pattern" or "failed test" which caused the reporter to attach comments for that run. When I run the entire suite, they are removed.
...b/components/CartPage/PriceAdjustments/__tests__/__snapshots__/priceAdjustments.spec.js.snap
Outdated
Show resolved
Hide resolved
@@ -160,7 +159,8 @@ test('renders a full page with onlineIndicator and routes', () => { | |||
}; | |||
const { root } = createTestInstance(<App {...appProps} />); | |||
|
|||
getAndConfirmProps(root, Navigation); | |||
// TODO: Figure out how to mock the React.lazy call to export the component |
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.
Hey dude, is this still valid given you have added a react mock in venia-ui
mocks?
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.
Yes. There is no Navigation
component, just the stringified version of the React.lazy callback.
Signed-off-by: sirugh <rugh@adobe.com>
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.
Nice work buddy. Couple of minor questions but mostly it is ready for QA.
...venia-ui/lib/components/CheckoutPage/PaymentInformation/__tests__/paymentInformation.spec.js
Show resolved
Hide resolved
resolver: directory | ||
directory: | ||
resolver: inline | ||
inline: './templates' |
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.
Hey, dude thanks for taking care of this. But I would suggest checking with the community if someone is using them or if we are missing something?
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.
These have not been used in PWA Studio since September 2019, after we swapped to the webpack template.html
file. Anyone who was on the version from before then and updates since then, will have had to do this upgrade. This is just removing the files that aren't hooked up to anything.
Signed-off-by: sirugh <rugh@adobe.com>
82cc606
to
009da4d
Compare
@sirugh Lighthouse score on desktop looks good but mobile still shows unused js warning, pls check - |
@dpatil-magento, are you saying that desktop and mobile have different lighthouse scores? That's odd. Either way, in the PR description I did try to clarify why there is still unused js:
|
Mobile would nearly always be lower as you have the same time targets with less bandwidth and less cpu. Still anything improving desktop should also improve mobile. Would love to see this merged with further efforts coming in additional prs. |
@fooman yes, in reality, but does lighthouse throttle automatically? If so that would explain it :) |
Depends on how you run it. But for example via Google Chrome the result will show what throttling was applied or via webpagetest.org |
So looking at the results via https://webpagetest.org/ and comparing it to PR3000 this PR looks to be an improvement https://webpagetest.org/result/210220_DiG7_13e1bbb50b7351e69bc60f1c6a16853b/ First Contentful Paint Largest Contentful Paint Lighthouse score As always these are to be taken with a grain of salt as when you compare the time to first byte there is big difference too which I believe is the time to serve index.html (which should be very much the same between these two PRs): |
I reran the above PR 3000 First Contentful Paint Largest Contentful Paint Lighthouse showing the variability of results (I believe a lot may be driven by how the PRs are hosted) and this time not a clear cut improvement. (lighthouse score up but Largest Contentful Paint 6 seconds slower!) This PR First Byte First Contentful Paint Largest Contentful Paint Lighthouse To run any tests like the above having a hosted version on a production like environment will probably give the best indication how much of an improvement there is. |
@sirugh @fooman WPT results are might depend on backend performance also. Here I compared 3 instances and this PR instance looks better. But @sirugh any reason js byte size is more on this pr https://www.webpagetest.org/video/compare.php?tests=210223_DiAX_2d42c6d682b41cde18176b657f3ae906,210223_DiXG_8ffb29c506015a3c670612e84235d0d2,210223_DiTF_b9a81f142cab77a940def48ca0fdfaf9 ? |
@dpatil-magento without any investigation, my gut reaction is that this is because we are now creating more chunks which means more boilerplate JS. |
With more chunks the JS minification will not be able to create as many savings. And indeed that's probably the more succinct way to say it @dpatil-magento with fluctuating backend performance the frontend can be hard to isolate. |
…-load-unused-bytes
Given its a balanced approach going ahead with this. QA Approved |
Description
Our main
client
andvendor
bundles are pretty large. There are savings (130k split from this PR alone!) to be had by splitting code that is unnecessary for the first render. That would include things like modals, drawers, drop downs, etc. The majority of changes in this PR are just addingReact.lazy
to components that aren't necessary on first render, and wrapping their implementations in<Suspense>
.Note: Much of the remaining unused bytes are from dependencies that we must load at start, such as Apollo, but for whatever reason do not tree-shake. Other bytes are from our implementation of ContextProviders which expose a lot of unnecessary actions in the main bundle. Further work is necessary to trim out that deprecated code. Definitely more work than is in the scope of this specific ask.
Testing these changes proved more difficult than I would have liked. Kent Dodds has a way around testing Suspense/Lazy but we don't have react-testing-library at our disposal right now. The current approach (mocking
React.lazy
) is a stop-gap.Related Issue
Closes PWA-1109.
Acceptance
Verification Stakeholders
Specification
Verification Steps
Screenshots / Screen Captures (if appropriate)
Develop Category Page


"Improved" Category Page
Checklist