This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/3.x by this push:
new 91de482 Opimtize key tree stemming by using maps instead of sets
91de482 is described below
commit 91de482fd66f4773b3b8583039c6bcaf1c5727ec
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Mon Mar 21 13:32:31 2022 -0400
Opimtize key tree stemming by using maps instead of sets
sets to due to a compiler bug in 22 consumes too much memory and is slower
on Erlang 22+
Reproducer: https://gist.github.com/nickva/ddc499e6e05678faf20d344c6e11daaa
With sets:
```
couch_key_tree:gen_and_stem().
{8,6848.812683105469}
```
With maps:
```
couch_key_tree:gen_and_stem().
{0,544.000732421875}
```
---
src/couch/src/couch_key_tree.erl | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/couch/src/couch_key_tree.erl b/src/couch/src/couch_key_tree.erl
index 84c7861..6c8637b 100644
--- a/src/couch/src/couch_key_tree.erl
+++ b/src/couch/src/couch_key_tree.erl
@@ -496,7 +496,7 @@ stem(Trees, Limit) ->
{NewSeen, NewBranches} = stem_tree(Tree, Limit, Seen),
{NewSeen, NewBranches ++ TreeAcc}
end,
- {sets:new(), []},
+ {#{}, []},
Trees
),
lists:sort(Branches)
@@ -553,11 +553,11 @@ stem_tree(Depth, {Key, Val, Children}, Limit, Seen0) ->
end.
check_key(Key, Seen) ->
- case sets:is_element(Key, Seen) of
- true ->
+ case Seen of
+ #{Key := true} ->
throw(dupe_keys);
- false ->
- sets:add_element(Key, Seen)
+ _ ->
+ Seen#{Key => true}
end.
repair_tree(Trees, Limit) ->