-
Notifications
You must be signed in to change notification settings - Fork 116
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
Add cache #47
Add cache #47
Conversation
@import "test/fixtures/imports/foo.css"; | ||
@import "test/fixtures/imports/foo-recursive.css"; | ||
@import "imports/foo.css"; | ||
@import "imports/foo-recursive.css"; |
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.
this test should not be changed since the point of this one is to check that without from option, you can use a file from your cwd (which is the root of this project when running test from the root)
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.
Then I propose that the documentation should be altered to reflect that:
// `from` option is required so relative import can work from input dirname
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.
it say "input", not "cwd" which is correct. If you make from a file import "./stuff"
and provide the from option, the file might be found in the same dir as the original input, and this cannot be done if you don't provide the from option.
What is not correctly clear ?
There is a test for that
Line 62 in debda62
compareFixtures(t, "relative-to-source", "should not need `path` option if `source` option has been passed to postcss", null, {from: "test/fixtures/relative-to-source.css"}) |
ping @MoOx |
expected = read("fixtures/" + name + ".expected") | ||
t.equal(actual, expected, "read content from cache") | ||
t.end() | ||
}) |
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.
how is this testing that the cache has been used ?!
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.
The first process()
call puts the compiled output into the cache since cacheDir
has been specified.
The second process()
call rather than compiling the CSS again instead reads it from the cache.
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.
The test does not prove anything right now :/. We should probably add something to track the cache usage.
@MoOx The test has been updated to include a check of the cache's state. |
var cacheFileName = imports[cssFileName].cache; | ||
var cache = fs.readFileSync(cacheFileName, "utf8").trim() | ||
|
||
t.equal(output, cache, "should put output in cache") |
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.
we know here that the cache is written, how do we know the cache is being read after that ?
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'm sorry @MoOx, there's no way of knowing. It's a transparent cache. Unless you're suggesting that we should add a bunch of debug code to poll the internal state of the engine, which I would strongly advice against, we might as well close the PR because there's no way for me to satisfy this need. I know that the cache is hit by using breakpoints, I know that it returns a correct and consistent result, and I know that I get a 100ms performance increase when using it with a local project of mine, but there's no way for me to put that into a unit test.
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.
There is always a way. What about adding a simple map object with {file-requested: bool flag} to know if a requested file as been used from cache? Doesn't seems hard to do and this won't affect perfs.
If you don't know how to do it, I can probably handle that.
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 quite understand what you mean, but you're welcome to take a stab at it.
Fix plugins section of README
I was about to merge that to handle the missing test but we made some changes in the master. Did you want to handle the rebase? Otherwise I will try to do it on tuesday. |
Fix warnings
@andyjansson you gonna' rebase this one? |
@andyjansson did you see #62? I basically handled the rebasing there. You can cherry-pick my commits. |
@jedmao you should probably PR to my repo |
Don't merge this yet. I need to verify that the cache works as intended. |
@jedmao Enabling caching for all tests and running the tests twice causes |
test/fixtures/*.actual.css | ||
test/cache |
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.
We have a duplicated line here that needs to be removed.
Are you familiar w/ how to rebase? The merge commits in this PR are, I think, something we want to avoid. |
See #63 for a clean rebase w/o merge commits. Feel free to submit a PR to my cache branch with the failing test you're talking about. I'm not sure what the issue is there. |
@jedmao It's not ready to be merged, so there would be no point in squashing the commits before it is. Once the issue mentioned earlier has been resolved I'll do an interactive rebase. |
I'd like to see a failing build w/ the issue you're speaking of. |
@jedmao Just change line 19 of opts = assign({path: importsDir, cacheDir: cacheDir}, opts || {}) |
@andyjansson I see what you mean now. Unfortunately, I don't know enough about how the caching works to really offer any help. My involvement in this PR was in response to #59 (comment), to get the ball rolling with my index.js refactor. FWIW, I'm getting the same failing test as you on the 2nd |
@jedmao Well, I finally had time to fix the bug, so the good news is that everything is working. The bad news is that the fork is now behind the upstream repo, which is why appveyor is reporting an error. |
May I ask why this was closed? Does it not work correctly, would it need more work on the PR (rebasing it again), or do you think it would not provide any significant advantage over the improvements that have already been made? It seems to me that #152 only achieves parts of what a more general caching approach would (only caching file I/O, but not any transformations applied after that). Using postcss-devtools, I found that postcss-import takes ~20 seconds in my project (accumulated over multiple CSS entry points), which is the vast majority of the overall build time. So any speedup would be great, and I'd be motivated to help if desired. |
@poeschko This PR was closed because of merge conflicts. Since then, the entire codebase was rewritten. No one ever attempted to replicate this feature. I'd welcome any performance improvements. There's two big performance problems in postcss-import:
I'm not sure which problem is the biggest slowdown. |
@poeschko I closed the PR because I felt the feature was never going to get merged in, so I switched my focus to other things. |
This feature would be amazing. Especially in my case because I am importing src from a node module which adds a huge delay to my app. |
This would be a great addition. |
Added a
cacheDir
option. When set, it will enable the cache functionality and store the compiled output(s) along with a dependency graph in the specified directory. Modifying any of the files in the dependency graph invalidates the cache for that file and any dependents. Any unmodified dependencies will continue to be cached.