You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2023/11/10 20:53:35 UTC

(couchdb) branch update-ets-lru-to-use-refs created (now 40a4df651)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch update-ets-lru-to-use-refs
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 40a4df651 Replace unique_integer with a ref in ets_lru

This branch includes the following new commits:

     new 40a4df651 Replace unique_integer with a ref in ets_lru

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(couchdb) 01/01: Replace unique_integer with a ref in ets_lru

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch update-ets-lru-to-use-refs
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 40a4df651a0ae9487f6fd77d74ed8d04af60d38c
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Fri Nov 10 01:42:45 2023 -0500

    Replace unique_integer with a ref in ets_lru
    
    We don't really need a strictly monotonic integer, just a unique key for each
    atime and ctime entry. `unique_integer([monotonic])` is also a concurrency
    bottleneck as indicated the warning in [1].
    
    Even in a sequential context, it's slower:
    
    ```
    > timer:tc(fun() -> [erlang:unique_integer([monotonic]) || _ <- lists:seq(1,1000000)], ok end).
    {434637,ok}
    
    > timer:tc(fun() -> [make_ref() || _ <- lists:seq(1,1000000)], ok end).
    {322988,ok}
    ```
    
    [1] https://www.erlang.org/doc/man/erlang.html#unique_integer-1
---
 src/ets_lru/src/ets_lru.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ets_lru/src/ets_lru.erl b/src/ets_lru/src/ets_lru.erl
index 66bf24612..d77b36d4a 100644
--- a/src/ets_lru/src/ets_lru.erl
+++ b/src/ets_lru/src/ets_lru.erl
@@ -366,4 +366,4 @@ table_name(Name, Ext) ->
 
 -spec strict_monotonic_time(atom()) -> strict_monotonic_time().
 strict_monotonic_time(TimeUnit) ->
-    {erlang:monotonic_time(TimeUnit), erlang:unique_integer([monotonic])}.
+    {erlang:monotonic_time(TimeUnit), make_ref()}.