-
Notifications
You must be signed in to change notification settings - Fork 53
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
time latency per file #38
Comments
I would guess this is because it's recompiling your less/css/scss/javascript/coffeescript/ each page load. If you're not actively working with your SCSS/SASS + JS you can turn caching on: https://github.com/CodeSleeve/asset-pipeline/blob/master/src/config/config.php#L110 |
But the same thing also happens if I load precompiled coffee, less, Cache used alone gives more or less the same latency. I am learning and Can there be any method to first check if original files have changed This could reduce the load times when in active development.
|
"Can there be any method to first check if original files have changed before compiling and then send back a 304 not modified header if nothing changed in a particular file?" I would hope that it worked like that out-of-the-box--given that it's using Assetic which provides a simple built-in caching mechanism (see: https://github.com/kriswallsmith/assetic/blob/master/README.md#internal-caching). Looking through the code, it seems Asset Pipeline has some concept of caching as evidenced here:
But that doesn't quite cut the mustard and doesn't appear to use Assetic's built in AssetCache. So, I played around and took a shot at weaving in Assetics Caching approach , at around this part of the SprocketsRepository:
Using the above lines as a reference point, you can edit the relevant logic to look something like:
NOTES:
So, I thought this would work as-is. But, alas, it exposed what looks like a legitimate issue with Assetic whereby the MinifyCSS filter causes an exception to be thrown due to its having a closure. I looked into that and isolated the cause and started a discussion around a patch. You may wish to join that conversation here: kriswallsmith/assetic#501 So, if you don't want to wait around for the discussion, pull requests, and possible bug fixes before an eventual release (or not)... you can make the changes I suggest above AND the changes I propose over on the Assetic issues list (kriswallsmith/assetic#501), and it should work. I haven't fully tested it, but, it seems to not break and improves loading times. I am also not the maintainer here and I may be missing something big and obvious and stupid. So, please don't take my suggestions as anything more than the product of 45 minutes worth of poking around from a guy in the peanut gallery. Cheers. EDIT: Updated the notes. |
@evantishuk I actually didn't know about the internal caching from Assetic. I can definitely see the usefulness in caching on per file basis if you had lots of files that needed pre-processing. Also, I don't know how this would mesh with this proposal |
@kdocki from what I can tell, I don't think it would impact that proposal too much, if at all. Assetic's AssetCache looks at the pre-compiled file-data and determines if it needs to recompile or pass along the cached content. So, at worst you may have duplicate file-data between your cache folder and That seems like a good default behavior regardless of how many assets you're wrangling. Especially when using something like Bootstrap Sass which has a lot of overhead with the current approach. Of course, Assetic's AssetCache doesn't handle the MinifyCSS filter at present, so anything in that direction would have to wait for a fix on their end or come up with a workaround that avoids the whole closure issue. |
Jut tried it. There seems to be some improvement, but I feels it still not enough. From old avg load times of 24s has come down to 19s. Well its still huge for a local dev SPA . Lets hope something better comes out of this |
@karanits Which filters do you have configured and which are actually used on these time consuming requests? |
I have configured to use only Coffeescript and handlebars only. I have removed all non necessary paths also |
What Handlebar filter class do you use? Can you narrow it down to one of them? Maybe takeout the handlebars filter and try again? |
actually the filters doesnt matter. I had once pre-complied all coffeescripts and handlebar templates before hand and just used this to load the resulting js files. results being the same latency. i will try to do that again and see what happens |
FYI I am using codesleeve's handlebar plug-in. Before that I used to one |
I just tried only loading pre compiled coffee files. Used no filters. Same I also hard wrote the generated script tags in my blade view and copied all This just leaves one thing. File system is slowing things down. |
Sorry, I'm a little confused now. If you employed the AssetCache as above, it shouldn't recompile files if nothing changed. But, as you've explained, even when its precompiled and devoid of filters it's still slow. It's starting to sound like a peculiarity of your environment. Are you remote mounting to a development server or something? Can you publish an archive of your assets and structure so we can try to reproduce? |
Yup. That's what I am thinking. I have a laptop running windows 8 and A few days ago, I had wampserver on windows 8, before going virtual. Then Well my asset structure is similar to backbonerails.Com tutorials by Brain I am loading atleast 20 js files and most of them are less than 100 lines. I am sorry, I feel I am not helpful enough. |
When I get a chance, I'll try including a few dozen dummy plain JS and coffee files. My local environment is just straight-up Ubuntu, so it should provide a relatively "clean" test. I can also try on my remote dev server which has a lot more horsepower and see how that responds. Even if it turns out that your environment is likely to blame, this discussion (I think) could lead to some real improvements! |
@kdocki a fellow over on the Assetic project pointed out that the First, adjust the SprocketsRepository to use Assetic's AssetCache (#38 (comment)), from above:
Second, the filters should implement
Maybe there's a better way to structure it. I've tested this approach and it works like a charm. If you have a better way to organize and implement the HashableInterface, let me know. Otherwise, I'd be happy to adapt these filters and make a pull request. |
@evantishuk Thanks for looking into this! :) Did you see an issue too? Also did this HashableInterface will fix the issue if you were able to reproduce it? If so and you want to make those changes ... put in a pull request and I'll definitely push it through. |
Well... I am going to try to put in some of these changes @evantishuk mentioned and test it... I'm not familar with Assetic Cache stuff but I'd like to see if it helps any. @karanits right now one thing you can do is set |
Concatenation does bring down the load time. But it makes debugging a lot Out of frustration I exported the virtual server to another pc and there So some of the issue may be with my laptop being over worked. But still I |
No, I haven't been able to reproduce the issue as described. :( I can rope in a bunch of JS and CSS and it will indeed chunk about 2 - 4 seconds (annoying, but acceptable IMHO). Nothing in the 20+ second range though.
I don't know. It definitely improves performance in the average case though.
Karantis stated earlier that the previously suggested monkey-patch I suggested offered a small improvement but not a complete fix. General mood was that something peculiar to his I/O was responsible for the delay. I'm leaning toward his case being rare unless another issue like this gets reported.
Let me know how that goes. I think it's the "right" way to do it. I suppose it should probably be the default behavior with a boolean config variable to turn it off in debug mode or explicitly. Also, I'm curious how best to organize the file structure given the |
An update: upon rechecking the edits @evantishuk has mentioned. I noticed my stupid mistake. I forgot to comment out
Now upon rechecking. I have 60+ assets which are a mix of coffee-scripts and handlebar templates. I get 10sec with no concat and 3sec with concat. |
Several things I noticed when testing the Assetic-first caching integration: First, if you have your CSS manifest looking for, say,
The cache does not know if Second, Assetic allows for a number of possible caching methods https://github.com/kriswallsmith/assetic/tree/master/src/Assetic/Cache (apc, array, file, expiring, etc). This is nice but should these options be exposed through Asset Pipeline? Third, Assetic could make clearing the cache a challenge. For instance, it's not obvious at all to me if it's feasible or even possible to manually clear the cache that's generated through Assetic. There is a method for removing a cached key (https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Cache/FilesystemCache.php#L57) but, the function that generates the key is private (https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Asset/AssetCache.php#L147) and doesn't appear to return the key anywhere outside of that class. Short of mirroring that cache key function within AssetPipeline, I don't see how we could integrate it into the CLI option. I've posted the question (kriswallsmith/assetic#501 (comment)) and hopefully I'm just sleep deprived and missing something obvious. Fourth, does leveraging the caching methods in Assetic possibly change how caching is done elsewhere in this package? Maybe a bigger question is should we explore making a full use of Assetic's tools and possibly refactor a bunch of existing code? Or maybe stop looking at Assetic and just continue to roll our own? |
I'm consolidating this issue into #34 so that I don't have multiple issues open. I am going to spend some time experimenting ways to speed up asset pipeline when you have many assets. I'd like to be able to accommodate at least match Rails speed (it can load ~200 assets in 3 second page refresh on my machine). |
Average time taken to load per file is around 1 second for me! does anybody else facing this even on fresh install
The text was updated successfully, but these errors were encountered: