-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
persistent cache relative paths #10400
Comments
I think it is good idea |
Yes, great. Here are some ideas for that:
|
I also thought about this. I will try to implement this using this approach |
For debugging you can use |
I have started implementing this feature and got some problems/questions. First of all what I already did:
Problems:
or better to create classes for that aka
Do I need to craft regexp to replace all absolute paths in one place (in store/restore methods)? Actually don't know better way for now.. |
I don't know will v8 create another hidden class using such implementation. However, we can instead of marking storing such Set/Map in |
I think that for the first step you just should add two additional methods to the cache context: writeAbsolute(context, value) {
if (value instanceof Set) {
const newSet = new Set();
for (const item of value) {
newSet.add(contextify(context, item));
}
return this.write(newSet);
}
if (value instanceof Array) {
return this.write(value.map(item => contextify(context, item)));
}
this.write(contextify(context, value));
}, and readAbsolute(context) {
const value = this.read();
if (value instanceof Set) {
const newSet = new Set();
for (const item of value) {
newSet.add(absolutify(context, item));
}
return newSet;
}
if (value instanceof Array) {
return value.map(item => absolutify(context, item)); // or just modify existing array
}
return absolutify(context, value);
}, And then replace all the place that writes a value with absolute path/paths |
Problem is that there are objects with absolute paths as property or property of a property.. e.g. https://github.com/webpack/webpack/blob/master/lib/Module.js#L823 So question was do I need to extract all paths:
or provide ability to serialize paths correctly for Set/Map serializers |
That looks weird to me. I would better go with the This can also be used for nested values e. g. inside of buildInfo
I don't think it makes sense to alter the default Set/Map serializers for absolute path. |
Beside simple relative path usage in cache, there is another problem that some build configuration can use This can also break cache since webpack request contains all loader urls, we should have a chance to fix this as well. |
This PR should fix it =) |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Still valid |
bump |
I've been paying attention to this issue. When we can use file caching in our CI process, it will give us a qualitative increase in build speed. I'm really looking forward to the experts here solving this problem. Thank you very much |
You can use file caching in CI. Just make sure that the absolute paths are consistent between CI builds. |
Perfect! I use __dirname to get the current compiled directory, and then generate the same cache file to compile the directory, and it works! Thank you very much. One word woke me up ! |
hi,Can you describe the process,about how we "generate the same cache file to compile the directory" |
Just bumping the issue here.
We allocate different runners and have a specific logic to build our (large) project in randomly named directories to avoid overlaps. It's quite difficult in this context to run every builds in the same absolute path for every pipelines we have. So this would be amazing to be able to have the cache without doing pirouettes 🤸♂️ with the directories in the CI. |
I was quite surprised when my prebaked webpack cache was not used in Github Codespaces. I've tracked it down to the cache using absolute paths. I would love the cache stay valid when moving the project directory or downloading a prebuilt cache folder, it would make things easier. |
I have started to look into this as well -- I wonder if the best route is to track down and contextify everywhere using absolute paths, or if there may be a lower level solution within the serializer/middleware itself. I suspect starting on the contextifying will eventually make evident if there is a better way to approach the problem. To start, I was thinking of tackling the FileSystemInfo cache - I saw @vankop did some similar work a bit over a year ago. Seems like that may be a good place to pick back up. On that note, I wonder if making the |
this will not help much if you want to put cache in git. Cache is not deterministic, so your git history will grow with random changes in cache files.. for ci there is solution already
|
How do you make sure that the paths are consistent if CI is running tests is uniquely generated directories? |
Is there a library I could parse the cache file to rewrite the paths? In our case, only one fragment of the path changes. It would be a matter of a simple replace operation. |
no.. |
Turns out I can just do You could also probably figure out how to manipulate the file using |
To make cache portable from VCS we need to implement "relative path" + "deterministic" cache features. Since we don't want to implement deterministic cache ( this feature will reduce cache performance a lot ) we decided to not implement this either. We will improve docs with some guides to most popular CIs how to setup cache there ( e.g. gitlab ci cache ) |
When gitlab CI has parallel build requirements, although the cache obtained is correct, the build path will be different, because CI builds will add job-Id by default. To solve this problem, it should also be necessary to fix the parallel task packaging path. |
'sed' not work for me,could you tell me how to reslove it! |
Feature request
What is the expected behavior?
right now cache writes absolute paths
What is motivation or use case for adding/changing the behavior?
if all paths will be relative to cache folder it will allow to share cache
How should this be implemented in your opinion?
Did not investigate this, yet
Are you willing to work on this yourself?
Yes
The text was updated successfully, but these errors were encountered: