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

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new 46a781fdc Replace unique_integer with a ref in ets_lru
46a781fdc is described below

commit 46a781fdcec064f73445797ef7653b98b86e4782
Author: Nick Vatamaniuc <vatam...@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()}.

Reply via email to