GetDocumentsWithIdStartingWith optimization

64 views
Skip to first unread message

Jesús López

unread,
Aug 1, 2012, 8:39:41 AM8/1/12
to rav...@googlegroups.com
Hi,
 
I have written a new overload of GetDocumentsWithIdStartingWith method which is faster than the original. This overload takes lastReadId instead of start parameter:
 
public IEnumerable<JsonDocument> GetDocumentsWithIdStartingWith(string idPrefix, string lastReadId, int take)
 
Reading 200000 documents with a page size of 1000 documents using ESENT takes nearly half time. The culprit of such a improvement is this piece of code that can be avoided:
 
 
while (start > 0)
{
 if (Api.TryMoveNext(session, Documents) == false)
  return Enumerable.Empty<JsonDocument>();
 start--;
}
 
 
I added the new overload to IDocumentStorageActions interface, implemented the method in both Raven.Storage.Managed.DocumentsStorageActions and Raven.Storage.Esent.StorageActions. I also added the method to Raven.Database.DocumentDatabase class.
 
Questions:
 
Would you accept a pull request?
Which additional classes would I need to modify to expose the new overload at the client side?
 
Thanks.
 
 

Oren Eini (Ayende Rahien)

unread,
Aug 1, 2012, 9:39:18 AM8/1/12
to rav...@googlegroups.com
Can you take a look at the latest unstable?
I fixed this issue already.

Jesús López

unread,
Aug 1, 2012, 10:34:56 AM8/1/12
to rav...@googlegroups.com
I thought I were using the latest unstable. It isn't this?:
 
 
I see the same culprit code.
 

El miércoles, 1 de agosto de 2012 15:39:18 UTC+2, Oren Eini escribió:
Can you take a look at the latest unstable?
I fixed this issue already.

Oren Eini (Ayende Rahien)

unread,
Aug 2, 2012, 4:32:36 AM8/2/12
to rav...@googlegroups.com
Sorry, it got lost in the merging, fixed in the next build.

Oren Eini (Ayende Rahien)

unread,
Aug 2, 2012, 4:36:27 AM8/2/12
to rav...@googlegroups.com
Oh, I see, I made the fix for another function, not this.
Resolved anyway.

Jesús López

unread,
Aug 5, 2012, 5:54:28 AM8/5/12
to rav...@googlegroups.com
Oren,
 
Now this method seems buggy.
 
do
{
Api.MakeKey(session, Documents, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey | MakeKeyGrbit.SubStrLimit);
if (Api.TrySetIndexRange(session, Documents, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive) == false)
return Enumerable.Empty<JsonDocument>();

if (TryMoveDocumentRecords(start, backward: false))
return Enumerable.Empty<JsonDocument>();

optimizer.Add();

} while (Api.TryMoveNext(session, Documents) && optimizer.Count < take);
 
 
You are moving on each iteration which seems wrong.
You are also making the key on each iteration which also seems wrong.
 
 
I also would like to point out that TryMoveDocumentRecords returns false when it success which is odd.

Oren Eini (Ayende Rahien)

unread,
Aug 5, 2012, 8:10:51 AM8/5/12
to rav...@googlegroups.com
Correct on both counts, thanks for that.
I'll have a fix soon.
Reply all
Reply to author
Forward
0 new messages