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

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

bug#48841: fido-mode is slower than ido-mode with similar settings


From: Dmitry Gutov
Subject: bug#48841: fido-mode is slower than ido-mode with similar settings
Date: Fri, 11 Jun 2021 05:19:03 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

On 07.06.2021 11:52, João Távora wrote:

    Maybe moving all of them to parameters and return values (making it a
    static function and having the caller manage state) would help, I
    haven't tried that exactly.


Normally, in those adventures you end up with the same allocations somewhere else, and uglier code. But you can try.

I have it a try, with little success (patch attached, for posterity). Since there's no multiple value returns in Lisp, I had to define a container for the three values.

The performance is basically the same, which seems to indicate that either Elisp has to allocate very little for a compiled lambda code, or it's optimized out (which would also make sense: the only thing necessary for it is a new container for the current scope).

     > Might be noise, or you might be thrashing of CPU caches, who
    knows? If
     > the string length is on the same cache line as the contents of the
     > string you're reading, then evicting that to go read the value of a
     > boxed integer somewhere radically different is slow.

But the string value is boxed as well, right?

The key is locality. If the string length and data happen to live nearby in memory (in the same box, so to speak), there's a decent chance that reading one brings the other into the cache, and you get a nice hit depending on your subsequent operation.

Here I'm just speculating, as I said. In managed languages such as Lisps, it's somewhat unpredictable. It's also always hardware dependent. Though given C/C++, a known processor and the right application, this will make a world of a difference, and will yield truly "weird" results (which arent weird at all after you understand the logic). Like, for example a vector being much better at sorted insertion than a linked list. (!) Look it up. Bjarne Stroustrup has one of those talks.

When you have to do some work, better memory locality can indeed change a lot. But in this case we have an already computed value vs. something the code still needs to compute, however fast that is.

Accessing function arguments must be currently much faster than looking up the current scope defined with 'let'.

Anyway, looking at what else could be removed, now that the extra allocation in 'match-data' is gone, what really speeds it up 2x-11x (depending on whether GC kicks in, but it more often doesn't), is commenting out the line:

  (setq str (copy-sequence str))

So if it were possible to rearrange completion-pcm--hilit-commonality not to have to modify the strings (probably removing the function altogether?), that would improve the potential performance of c-a-p-f quite a bit, for fido-mode and other frontends (depending on how much overhead the other layers add).

Ultimately, the scoring information doesn't have to live in the text properties. For sorting, the frontend could allocate a hash table, then ask the [backends? styles?] for completion scores on each item and sort based on that. Since faces are needed only for the completions that are currently displayed, even having to repeat the regexp matching stuff for each of them later would be no big deal performance-wise, compared to the current approach.

Anyway, these are musing for the much-discussed future iteration of the API. With the current version, and tied by backward compatibility, it might be possible to wring 10ms of improvement by consolidating text property changes somehow, but likely no more than that.

Looking forward for your analysis of fido-vertical-mode's performance improvement over the "normal" one.

Attachment: completion-pcm-score-struct.diff
Description: Text Data


reply via email to

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