Fastest way to update a document

Hi, as there are many different ways to update a document with CBL (on android), I was asking myself, what the fastest method is.

In my case the document needs to be updated once every second. It will only be updated from one client, so conflicts are not an issue.

Using a DocumentUpdater, creating a new Revision or just call putProperties? Or are there even more?

Hi @Mav3ric,

I use putProperties most of the time unless I have to include an attachment in which case I use the Revision api and the setAttachment method. I don’t think there’s a difference in performance between the two but I may be wrong.


Hi @Mav3ric,
If you needs to update multiple documents at once, please try to use Database.runInTransaction(TransactionalTask).


the document does not have any attachments and it’s the only one that is updated regularly.

I made a few Unit tests to determine the times, but the differences are all minimal and also not constant. In one run, one method was the fastest, in the next it is the slowest. I also tried different numbers of updates (10 to 2000) per method and tried to put sleeps in between them and tried it with and without the sync gateway connected.

So I guess I will just keep using putProperties then.

Another question in this topic: I only need the latest revision of this document, so they wouldn’t need a history. I know that I can set the max. revision history on the database, but can I set it on single documents? Or would it be a good idea to always delete the old revisions?