Skip to content
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

Closed
wants to merge 15 commits into from
Closed

Add cache #47

wants to merge 15 commits into from

Conversation

andyjansson
Copy link

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.

@import "test/fixtures/imports/foo.css";
@import "test/fixtures/imports/foo-recursive.css";
@import "imports/foo.css";
@import "imports/foo-recursive.css";
Copy link
Contributor

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)

Copy link
Author

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

Copy link
Contributor

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

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"})

@andyjansson
Copy link
Author

ping @MoOx

expected = read("fixtures/" + name + ".expected")
t.equal(actual, expected, "read content from cache")
t.end()
})
Copy link
Contributor

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 ?!

Copy link
Author

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.

Copy link
Contributor

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.

@andyjansson
Copy link
Author

@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")
Copy link
Contributor

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 ?

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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.

@MoOx
Copy link
Contributor

MoOx commented Jun 21, 2015

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.

@MoOx MoOx mentioned this pull request Jun 21, 2015
@jednano
Copy link
Contributor

jednano commented Jun 24, 2015

@andyjansson you gonna' rebase this one?

@andyjansson
Copy link
Author

@jedmao I tried. I give up. I'll leave this to @MoOx

@jednano jednano mentioned this pull request Jun 24, 2015
@andyjansson
Copy link
Author

@MoOx @jedmao I have a working version based on the latest source, however I haven't rebased the project. I'm thinking it might be easier to just create a new fork and add the code there. What do you think?

@jednano
Copy link
Contributor

jednano commented Jun 27, 2015

@andyjansson did you see #62? I basically handled the rebasing there. You can cherry-pick my commits.

@andyjansson
Copy link
Author

@jedmao you should probably PR to my repo

@andyjansson
Copy link
Author

Don't merge this yet. I need to verify that the cache works as intended.

@andyjansson
Copy link
Author

@jedmao Enabling caching for all tests and running the tests twice causes should be able to consume npm package or local modules to fail. It looks like it isn't ignoring an @import declaration for an already imported document. Having another set of eyes on this issue would be swell.

test/fixtures/*.actual.css
test/cache
Copy link
Contributor

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.

@jednano
Copy link
Contributor

jednano commented Jun 28, 2015

Are you familiar w/ how to rebase? The merge commits in this PR are, I think, something we want to avoid.

@jednano jednano mentioned this pull request Jun 28, 2015
@jednano
Copy link
Contributor

jednano commented Jun 28, 2015

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.

@andyjansson
Copy link
Author

@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.

@jednano
Copy link
Contributor

jednano commented Jun 28, 2015

I'd like to see a failing build w/ the issue you're speaking of.

@andyjansson
Copy link
Author

@jedmao Just change line 19 of test/index.js to the following and run npm test twice:

  opts = assign({path: importsDir, cacheDir: cacheDir}, opts || {})

@jednano
Copy link
Contributor

jednano commented Jul 1, 2015

@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 npm test run.

@andyjansson
Copy link
Author

@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.

@poeschko
Copy link

poeschko commented May 3, 2017

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.

@RyanZim
Copy link
Collaborator

RyanZim commented May 3, 2017

@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.

@andyjansson
Copy link
Author

@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.

@tqwewe
Copy link

tqwewe commented Feb 23, 2019

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.

@AndyOGo
Copy link

AndyOGo commented Dec 11, 2020

This would be a great addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants