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 2022/03/21 17:35:45 UTC

[couchdb] branch optimize-key-tree-using-maps created (now 2908b8d)

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

vatamane pushed a change to branch optimize-key-tree-using-maps
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 2908b8d  Opimtize key tree stemming by using maps instead of sets

This branch includes the following new commits:

     new 2908b8d  Opimtize key tree stemming by using maps instead of sets

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: Opimtize key tree stemming by using maps instead of sets

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

vatamane pushed a commit to branch optimize-key-tree-using-maps
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 2908b8de4c9c17257cebae4a21b2eed2c1b2565e
Author: Nick Vatamaniuc <va...@gmail.com>
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) ->