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

DB#range seems to scan over the end of range #18

Open
ogibayashi opened this issue Oct 16, 2014 · 0 comments
Open

DB#range seems to scan over the end of range #18

ogibayashi opened this issue Oct 16, 2014 · 0 comments

Comments

@ogibayashi
Copy link

Hello.

It seems that DB#range scans over the end of range and affect performance.
I think stop iterating after the upper limit is better.

Here is the result of my test. Key is the sequence of "0000001" to "5000000" and value is just fixed string of 2KB size. If I specify the range of first ten keys, it takes 537 seconds. This is because DB#range does not stop scanning after the key "0000010". If I specify the range of the last 2 keys, it returns quickly.

2.1.2 :004 >  Benchmark.measure{db.range("0000001","0000010"){|k,v| puts k}}.to_s
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
0000010
 => "498.380000   8.610000 506.990000 (537.246030)\n" 

2.1.2 :009 >   Benchmark.measure{db.range("4999999","5000000"){|k,v| puts k}}.to_s
4999999
5000000
 => "  0.000000   0.000000   0.000000 (  0.001968)\n"

Maybe, stop iterating after the end of the range would be better? (like below)

--- iterator.rb.bak     2014-10-15 11:09:30.378246696 +0900
+++ iterator.rb 2014-10-15 11:48:56.200251049 +0900
@@ -29,6 +29,7 @@
     def each(&block)
       return self unless block_given?
       if current = self.next
+        break if range? && current[0] >= @_range[1]
         block[*current]
       end while valid?
       @_range = nil
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

No branches or pull requests

1 participant