You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "pgj (via GitHub)" <gi...@apache.org> on 2023/07/13 15:32:49 UTC

[GitHub] [couchdb] pgj commented on a diff in pull request #4659: fix(`mango`): remove duplicate elements from `indexable_fields/1` results

pgj commented on code in PR #4659:
URL: https://github.com/apache/couchdb/pull/4659#discussion_r1262734010


##########
src/mango/src/mango_idx_nouveau.erl:
##########
@@ -307,7 +307,7 @@ construct_analyzer({Props}) ->
 
 indexable_fields(Selector) ->
     TupleTree = mango_selector_text:convert([], Selector),
-    indexable_fields([], TupleTree).
+    ordsets:to_list(indexable_fields(ordsets:new(), TupleTree)).

Review Comment:
   If I recall correctly, this method was chosen based on a discussion on the topic on Slack.  But I might have misunderstood that.  Either way it happened, I have done some simple measurements to see which approach is faster.  Although I believe you meant `lists:usort/1`?  The `lists:ukeysort/2` function seems to work with tuples only.
   
   ```console
   > Xs = lists:map(fun(_X) -> rand:uniform(1000) end, lists:seq(1, 10_000)).
   [153,53,32,94,647,739,807,484,695,434,934,437,149,888,853,
    251,639,101,838,404,236,68,187,350,467,162,1000,775,930|...]
   > element(1, timer:tc(fun() -> ordsets:to_list(lists:foldr(fun(X, Acc) -> ordsets:add_element(X, Acc) end, ordsets:new(), Xs)) end)) / 1000.
   63.81
   > > element(1, timer:tc(fun() -> lists:usort(lists:foldr(fun(X, Acc) -> [X | Acc] end, [], Xs)) end)) / 1000.
   11.752
   ```
   
   The results suggest that the use of `ordsets` is not justified here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org