Do not commit read-only transactions
This might save a round-trip to the network thread [1]. It also follows the
recommendation in the C api docs [2].
[1] https://forums.foundationdb.org/t/performance-of-read-only-transactions/1998
[2] https://apple.github.io/foundationdb/api-c.html#c.fdb_transaction_commit
However, it turns out in order for the watches to fire the read-only
transaction still has to commit, so avoid this optimization if has_watches(Tx)
is true.
diff --git a/src/erlfdb.erl b/src/erlfdb.erl
index 2b62b91..b50f843 100644
--- a/src/erlfdb.erl
+++ b/src/erlfdb.erl
@@ -653,7 +653,10 @@
do_transaction(?IS_TX = Tx, UserFun) ->
try
Ret = UserFun(Tx),
- wait(commit(Tx)),
+ case is_read_only(Tx) andalso not has_watches(Tx) of
+ true -> ok;
+ false -> wait(commit(Tx))
+ end,
Ret
catch error:{erlfdb_error, Code} ->
put(?ERLFDB_ERROR, Code),