Skip to content

Commit

Permalink
Replace unique_integer with a ref in ets_lru
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nickva committed Nov 10, 2023
1 parent 6d393ed commit 46a781f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ets_lru/src/ets_lru.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.

0 comments on commit 46a781f

Please sign in to comment.