Any time you wonder about slow performance in an iOS (or Mac) app, you should 
reach for Instruments and run the CPU Profiler.

>From looking at your code, I don’t see anything obvious. The map function 
>should be fast. NSPredicates aren’t terribly fast, but it shouldn’t take 5ms 
>to run that predicate. I’m curious to hear where Instruments says the 
>bottlenecks are.

However, that’s a poorly optimized query: it’s going to do a linear scan of the 
index every time it runs, instead of taking advantage of b-tree search. Your 
search criterion is the (fromId, toId) pair, so that’s what you should be 
indexing on. What I would do is
        emit( [min(doc.fromId, doc.toID), max(doc.fromID, doc.toId)], 
doc.messageDate )
Then query with key = [min(fromId, toID), max(fromID, toId)], and sort the 
results by row.value (which will be the date.)

In case it’s not clear: the reason for the min and max calls is to create the 
same key whichever order the fromId/toId appear in, since the query code you 
gave doesn’t care about the ordering.

—Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mobile-couchbase+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/3C9FA90E-CF46-4636-8240-5F38D154052C%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to