Просмотр исходного кода

perf(trie): do not call ets:info/2 to check if table is empty

emqx_trie table is a ordered_set, with write_concurrency set to
true, the counter is not centrialsed, the ets:info/2 call to
check size == 0 is very expensive
Zaiming Shi 4 лет назад
Родитель
Сommit
c81cd8550d
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      src/emqx_trie.erl

+ 1 - 1
src/emqx_trie.erl

@@ -122,7 +122,7 @@ match(Topic) when is_binary(Topic) ->
 
 %% @doc Is the trie empty?
 -spec(empty() -> boolean()).
-empty() -> ets:info(?TRIE, size) == 0.
+empty() -> ets:first(?TRIE) =:= '$end_of_table'.
 
 -spec lock_tables() -> ok.
 lock_tables() ->