|
From: | Dmitry Gutov |
Subject: | Re: What's missing in ELisp that makes people want to use cl-lib? |
Date: | Mon, 13 Nov 2023 00:09:02 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 |
On 12/11/2023 04:36, João Távora wrote:
cl-lib is not that well-optimized either.That's certainly true. I've been looking at the code and there are some serious optimization opportunities in cl-lib.el. The one you found right away, destructive versions delegating to overconsing non-destructive ones, but also other opportunities. I attach a patch that I hope you can try with that bug report. Very lightly tested here, but seems to show a measurable improvement.
Looks like a solid improvement: (setq cc (all-completions "" obarray)) ;; (length cc) => 46002 (defvar list2 '("abc" "abc" "abc" "abc" "abc" "abc")) (benchmark-run 10 (cl-set-difference cc list2 :test 'equal)) ;; => 0.430 (benchmark-run 10 (setq cc (cl-nset-difference cc list2 :test 'equal))) ;; => 0.137 (!) (benchmark-run 10 (my/set-difference cc list2)) ;; => 0.144 (benchmark-run 10 (seq-difference cc list2)) ;; => 0.814 (defun my/set-difference (list1 list2) (delq 'wrong (mapcar (lambda (c) (if (member c list2) 'wrong c)) list1)))So it seems on par with the hand-written version (byte-compiled, too) that hardcodes the test function.
Curiously, though, if I make list2 longer (e.g. 12 elements rather than 6), then my/set-difference starts to win noticeably (0.166 vs 0.200).
I'll keep the real-world case as-is (code in project--vc-list-files) both because the result with cl-nset-difference is still a little slower, and because it's slower in all released emacsen, but it definitely becomes an option.
[Prev in Thread] | Current Thread | [Next in Thread] |