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
Improve minChunkSize algorithm #4723
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#better-minchunksize or load it into the REPL: |
This PR has been released as part of rollup@3.5.0-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
Codecov Report
@@ Coverage Diff @@
## master #4723 +/- ##
==========================================
- Coverage 98.99% 98.97% -0.03%
==========================================
Files 219 219
Lines 7839 7878 +39
Branches 2171 2182 +11
==========================================
+ Hits 7760 7797 +37
Misses 26 26
- Partials 53 55 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
840ea6c
to
03fdcc0
Compare
This PR has been released as part of rollup@3.6.0-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
28465ce
to
ae77794
Compare
This PR has been released as part of rollup@3.6.0-1. Note that this is a pre-release, so to test it, you need to install Rollup via |
@gajus please give this PR another shot and report the results. |
3a100e1
to
439012b
Compare
Is this the If yes, this logs at build time:
and at runtime it breaks with
Removing |
This PR has been released as part of rollup@3.6.1-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
I see, I think I had some wrong assumptions here. I reworked the algorithm to explicitly avoid creating cycles within chunks, not module dependencies. Could you run it again with |
haven't had a chance to debug yet, but it is a new error at the moment:
|
I see. I will add some checks to look for pre-existing and introduced cycles. Will get back to you when that is ready. |
107fcdc
to
a3259be
Compare
This PR has been released as part of rollup@3.7.1-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
Ok, |
Build logs:
Runtime logs:
Is there anything in terms of logs that you were seeking for? |
Thanks, this answers my question. Need to think a little longer how to properly prevent the creation of cycles. But should be a solvable issue. |
c2834b8
to
c2de6b9
Compare
This PR has been released as part of rollup@3.7.3-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
Ok, I reworked the cycle prevention algorithm. Could you give |
👋 Let's see... Console output:
Same error as earlier though:
Let me know if I can provide any other useful information. |
2fd4b7a
to
1ee5d10
Compare
This PR has been released as part of rollup@3.7.5-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
Ok, I managed to reproduce the issue locally and hopefully found a way to fix the issue for good. Apparently, I was not tracking transitive dependencies correctly. I hope performance of the current solution is still ok. |
Unfortunately, same error. Happy to provide as much context as needed. |
So, no change in the number of cycles found? What are the logs? |
900fae0
to
b1c586f
Compare
✅ Deploy Preview for rollupjs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
8847d3a
to
56f717b
Compare
I removed the logging and will merge the changes from this branch into master and release them as I think they are still a net-improvement. But I guess we need to keep working on this feature. |
This PR has been released as part of rollup@3.13.0. You can test it via |
Can you use both |
@lukastaegert I've been heads down helping team to prepare for the upcoming launch, but now have a bit more time to debug this. For what it is worth, I can see from debugging our build that the issue is caused by a circular reference. I've removed all instances that were triggering I am making further code changes on our end to reduce the risk of circular dependencies. Will follow up once I know more. |
Removing all circular references from the codebase did not solve the issue. |
Exactly. It is possible that Not sure if this is any option, but if you can grant me temporary access to your code (under an NDA of course), I could debug it from there, which would be much simpler. I sent you a Discord message regarding this. |
I saw your message (sorry again for poor communication), and I've asked to evaluate what would it take to share access. The problem is that app is part of a mono repo that includes a lot of sensitive information. |
You know, I will just power through this and setup something. Might take a few days, but worth it. Will DM when ready. |
Still trying to get an isolated app to work. For what it is worth, the error that we are getting now is:
Which is slightly different than what it was before. It seems almost like there is a circular reference among react dependencies. |
@lukastaegert So some good news and not so good news. The not so good news is that I was not able to create an isolated example of what is breaking chunking. The good news is that while trying to create an isolated project, I narrowed down the issue to just one dependency. So we just need to figure out what that (internal) dependency is doing that is breaking chunking. |
Great stuff! I will report back with my findings. |
Heads up that this turned out to be mostly a false-positive finding. Sent an update through Discord. |
Hi. When I set As background, What puzzles me is how the chunking can trigger a bug here, so I will do some more digging. But maybe in the end, this can already be the solution. Otherwise, your reproduction is also a very good testing ground for build memory and performance improvements 😉 |
So, it is failing for a different reason now:
which refers to:
This looks like a fragment of React library, and |
Ah, that is very interesting. So it still seems to be related to some bug in the commonjs logic. If have some ideas for how I want to improve that plugin, I will try some things. |
When doing I just realized that it is merging page chunks, which is not desirable.
|
Why is that not desireable? Is there a logic that relies on these chunks being present? Or is it causing issues in other places? We can certainly implement some option on top to preserve certain chunks, but the implementation depends on what issues the merge causes. But the more chunks are excluded, the harder it will be to meet any size constraints. |
Also, please give #4851 a spin! |
Hi @lukastaegert great work on the algorithm, just one thing I noticed when working with both For example I can see the main function is referred here: rollup/src/utils/chunkAssignment.ts Line 279 in a7b36ca
Would you be open to exporting all those functions in that file so that it is possible to make use of it within the |
Not sure. On the one hand this is still experimental and can and will change a couple more times during upcoming releases. But the main problem is that the algorithm heavily relies on analytics done in other parts of chunking algorithm, while |
I just noticed that there are still scenarios where side effects are triggered earlier than they should, which may be the problem you are seeing. I have an idea how to fix this, will put this into #4851 |
Ok, I reworked #4851, maybe that addresses the issues you saw with page chunks. |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This PR improves the minChunkSize algorithm in several ways:
Even though we now have a step to merge chunks with side effects, it still requires a sufficient amount of pure chunks to be present, and there is no guarantee suitable merge partners are available. This PR also includes #4718 to allow to try out stuff.
It also contains some simple logging to get some numbers how many chunks were merged and which chunks were not merged.
@gajus would be nice if you could give this one a shot and report the results.