help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: return first element in list with certain property


From: Drew Adams
Subject: RE: return first element in list with certain property
Date: Tue, 21 Nov 2017 11:26:35 -0800 (PST)

> Please consider Knuth's statement about premature optimization. Until
> your users have actually complained about the speed of your product and you
> have benchmarked it and isolated cl-find-if as the culprit, there's no need to
> micro-optimize.

100% agreement.

> Presumably cl-find-if has performed two iterations for years
> or decades without anybody being bothered enough to improve it.

"Presumably ..."  No.

Yes, cl.el has been here for a long time.  But that doesn't
mean that everything in it is implemented as well as it
could be.

It was put together in a fairly short time, and it has _not_
had super heavy use over the years (that's my guess).

And yes, Emacs lisp use (including of CL emulation) is mostly
for Emacs, and most use cases do not involve things that need
high performance.  The number of cases where `cl-find' has
actually been used on very large lists is likely not so high.

Looking at the code, it seems that it would not be difficult
to improve this aspect, providing just a single traversal.
For the list case it could just use the catch-throw idiom,
for example.

So yes, not choosing to use `cl-find' in your Emacs-Lisp
code just because it traverses the list twice is silly and
is most likely premature optimization.

But fixing the `cl-find' implementation so that it does not
gratuitously traverse the list twice might not be silly.

As those tests communicated here so far have shown, `cl-find'
is anyway performant - no doubt partly because `elt' has a
C implementation.  Still, the double traversal is gratuitous,
and `cl-find' would be faster without it.

(Do I personally care about how fast it is?  Not really.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]