-
Notifications
You must be signed in to change notification settings - Fork 275
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
Inefficient check for empty directory in Shrine::Storage::FileSystem#clean #365
Comments
I have a few ideas how this could be improved:
What do you think? |
Thank you for such a detailed report! TIL about Regarding Ruby 2.3, it seems that it will be EOL'd at the end of this month already, so we can drop support for it in Shrine. |
I think, something like this could work: def empty_dir?(path)
Dir.foreach(path) { |x| return false unless ['.', '..'].include?(x) }
true
end |
Fixes shrinerb#365 Dir.empty? does not load all the child directories into memory. This improves the performance for directories with a lot of children.
@janko , sorry for intervention into this closed issue, but there are still a lot of applications, using Ruby 2.3.x. In fact, AWS Elastic Beanstalk is still supporting all the versions starting from Ruby 1.9. It's a pity and major inconvenience to not be able to use new Shrine versions since 2.16 with Ruby 2.3, given the impressive list of Shrine's new features, enhancements and fixes. So, is it possible a implementation of |
Curious what's keeping you from upgrading to ruby 2.4, when 2.3 is out of support? 2.3=>2.4 is normally a pretty painless upgrade. |
@jrochkind , at least Rails 3.2.x isn't working wit Ruby 2.4.x mostly because of the old version of json gem. Moreover, extensive use of FixNum is adding a lot of incompatibilities, because of the unifying of FixNum and BigInt into Integer in 2.4. |
Ah, Rails 3.2, that would explain it. Rails 3.2 is also end-of-lifed, receiving no support, not even security updates, from Rails maintainers. I understand that some are stuck on it anyway. I also understand when janko decides there's a very real cost to supporting this ancient unsupported versions, and we can't afford to. I wonder if you wanted to prepare a PR back-porting the fix into what could be like a, I dunno, shrine 2.16.1, if janko would be amenable to doing such a release. It's still confusing on the maintainer's end to keep track of such things. Running very old unsupported software is indeed challenging. |
When I dropped support for Ruby 2.3, I thought that was a completely fine support strategy, considering that Ruby 2.3 was EOL and that high backwards compatibility is maintained in 2.x versions. I haven't had any report (until now) of someone being stuck on Ruby 2.3 without the ability to upgrade. I would like for Shrine to still support Rails 3.2, so I'm open for adding back support for Ruby 2.3. However, I would like to first understand better why people on Rails 3.2 cannot upgrade to Ruby 2.4. @texpert Do you have some GH issues you could link me to? I would like to know more about the problem with older On the other hand, require "warning"
Warning.ignore([:fixnum, :bignum]) |
The only commit I was able to find was this one, so it appears there was zero cost in maintaining Ruby 2.3 support before this fix. And @RKushnir's 2.3-compatible approach looks straightforward. I will add Ruby 2.3 support back to Shrine. The latest Shrine version is 2.19.0, but the I will also bring back Ruby 2.3 support in |
Even though Ruby 2.3 is EOL, people still on Rails 3.2.x are stuck with Ruby 2.3, because Ruby 2.4 has some backwards incompatible changes with the JSON gem, and possibly other problems as well. #365 (comment) Since it's really not a problem for us to maintain Ruby 2.3 compatibility (at least for now), we add back support for Ruby 2.3. This will be backported into Shrine 2.19.1 as well.
Done ✅
|
Thank you very much, @janko for re-enabling Ruby 2.3 support!! As for GH issues, this is the issue of json gem - ruby/json#308. They've fixed compatibility with Ruby 2.4.x in json version 2.0.0, but the Rails team refused to backport changes to unsupported Rails 3.2.x - see Rails GH issue - rails/rails#27450. |
Even though Ruby 2.3 is EOL, people still on Rails 3.2.x are stuck with Ruby 2.3, because Ruby 2.4 has some backwards incompatible changes with the JSON gem, and possibly other problems as well. shrinerb#365 (comment) Since it's really not a problem for us to maintain Ruby 2.3 compatibility (at least for now), we add back support for Ruby 2.3. This will be backported into Shrine 2.19.1 as well.
Brief Description
Thank you for creating this great gem! We’ve been using it in production at @liefery for over half a year now and we’re happy with how extensible it is (especially with moving image processing to the background).
I noticed that a background worker which calls
Shrine::Attacher.delete(data)
takes a lot of time to execute (up to 2-3 minutes) and can allocate a lot of memory (up to 400-500 MB).I narrowed down the problem to cleaning empty directories in
Shrine::Storage::FileSystem
. I can see that it’s possible to disable it completely and that’s what we will do in the first place. However, I was wondering if it’s possible to improve the performance so we can re-enable it later.Shrine::Storage::FileSystem#clean
containspathname.children.empty
(shrine/lib/shrine/storage/file_system.rb
Line 145 in b92cddf
For us, the additional problem is that we use GlusterFS (network filesystem) so it's even slower.
Expected behavior
Checking for empty directory doesn't require loading directory content into memory.
Actual behavior
Checking for empty directory loads directory content into memory.
Our configuration
System configuration
Ruby version: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]
Shrine version: 2.16.0
The text was updated successfully, but these errors were encountered: