Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Rails 3.2.6 caching is inefficient on Windows #7254
Using jruby 1.7, Windows 7, Rails 3.2.6
When using config.reload_classes_only_on_change = true the checking of whether to reload a class takes a long time. This is likely as much a windows Issue as it is a Rails Issues, however it may be feasible to work around the issue.
On each request, including simple image requests, the file structure is scanned to see if any files have been added or updated. This scan is very slow on Windows. It is fine on the Mac and Linux.
The following line takes about 1/2 second per call with only about 10 folders in the list.
A possible solution is to cache the folders and only update them to include new files after a few seconds have elapsed. This code is possibly not thread safe, I am just providing it for an example. A single request that loads 20 images will now take a second or two to load instead of 10 seconds.
Once you have the file list (with only 113 file in it on my project) then it is very fast to actually check the file timestamps for changes.
This is about 4 times worse on JRUBY 1.7 than JRUBY 1.6 for me. It is probably related to bug:
If you precompile your assets the problem goes away, but then you have to recompile them when doing development in the view all the time.
On the mac this code is being executed for every image too, it is just that the problem is less severe as it is about 10 times faster. By using this fix the speed is still considerably improved.
Another possibility for my project is to reduce the number of assets by using image strips/sprite sheets. I'll look into this too.