From: Mathias Dahl <mathias.dahl@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Abbrev suggestions - feedback appreciated
Date: Sun, 17 May 2020 16:59:11 +0200 [thread overview]
Message-ID: <CABrcCQ4sPJPuEROVUoa6ifrkusXp3DnOoFH+Jy7TVzip1SkXpw@mail.gmail.com> (raw)
In-Reply-To: <jwvd073cl6g.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 6929 bytes --]
>
> I'm not suggesting to implement
> `abbrev-get-active-expansions` differently.
> I'm suggesting to implement something else. I.e.
>
> (defmacro abbrev-do-active-expansions (VAR &rest BODY)
> "Bind VAR to an active expansion and run BODY with it.
> Repeat it for all active expansions."
> ...)
>
> or
>
> (defun abbrev-mapc-active-expansions (FUNC)
> "Call FUNC on each active expansion."
>
> This way you don't need to build a list of active expansions: you run
> FUNC or BODY on each expansion when you encounter it.
>
Ah, of course, got it now! :) I tried a few versions of this now. I need to
go through
the complete list of active abbrevs/expansions since I want to find one
that is valid
and I also want to find the "best" one (according to what we discussed
before).
I defined 10,000 dummy abbrevs (a1 .. a10000) and used the profiler to
compare
memory usage and... I did not get any conclusive results. And between runs
I get different
memory values reported.
If I can draw any conclusions at all it would be that the old version (that
used another
function to get the active abbrevs) and the new one (that does what needs
to be done
while collecting the active abbrevs) are more or less the same, from the
perspective
on memory consumption.
Here is the original version, slightly modified. I added a new cache to
make the
abbrev-suggest-expansion-exist-at-point function not have to call
buffer-substring
for a certain length many times.
(defun abbrev-suggest ()
"Suggest an abbrev to the user based on the text before point.
Uses `abbrev-suggest-hint-threshold' to find out if the user should be
informed about the existing abbrev."
(interactive)
(abbrev-suggest-previous-chars-clear)
(let (abbrev-found)
(dolist (expansion (abbrev-get-active-expansions))
(when (and (abbrev-suggest-above-threshold expansion)
(abbrev-suggest-expansion-exist-at-point expansion))
(setq abbrev-found (abbrev-suggest-best-abbrev
expansion abbrev-found))))
(when abbrev-found
(abbrev-suggest-inform-user abbrev-found))))
One of the profiler runs:
Function Bytes %
- command-execute 6,191,706 99%
- call-interactively 6,191,706 99%
- funcall-interactively 6,191,706 99%
+ profiler-stop 3,178,331 51%
- abbrev-suggest 3,012,912 48%
- let 3,012,912 48%
- let 3,012,760 48%
- while 2,046,520 33%
- let 1,704,376 27%
- if 1,704,376 27%
- and 1,704,376 27%
- abbrev-suggest-expansion-exist-at-point 1,023,256 16%
- string= 1,023,256 16%
- abbrev-suggest-previous-chars 682,168 11%
+ let 1,048 0%
- abbrev-get-active-expansions 966,240 15%
- let 966,240 15%
- let 966,240 15%
- while 966,240 15%
- let 966,240 15%
- mapatoms 966,240 15%
- #<lambda 0x19941c7d83254423> 870,144 14%
- let 771,936 12%
- symbol-value 675,840 10%
- abbrev--symbol 483,648 7%
+ let* 289,344 4%
+ if 96,096 1%
+ if 152 0%
Here is the new version:
(defun abbrev-suggest ()
"Suggest an abbrev to the user based on the text before point.
Uses `abbrev-suggest-hint-threshold' to find out if the user should be
informed about the existing abbrev."
(interactive)
(abbrev-suggest-previous-chars-clear)
(let (best-abbrev)
(dolist (table (abbrev--active-tables-including-parents))
(mapatoms (lambda (e)
(let ((value (symbol-value (abbrev--symbol e table)))
abbrev)
(when value
(setq abbrev (cons value (symbol-name e)))
(when (and (abbrev-suggest-above-threshold abbrev)
(abbrev-suggest-expansion-exist-at-point
abbrev))
(setq best-abbrev (abbrev-suggest-best-abbrev
abbrev best-abbrev))))))
table))
(when best-abbrev
(abbrev-suggest-inform-user best-abbrev))))
Here is a run with the profiler of the above:
Function Bytes %
- command-execute 4,996,751 99%
- call-interactively 4,996,751 99%
- funcall-interactively 4,996,751 99%
+ profiler-stop 3,179,816 63%
- abbrev-suggest 1,816,472 36%
- let 1,816,472 36%
- let 1,815,264 36%
- while 1,815,264 36%
- let 1,815,264 36%
- mapatoms 1,815,264 36%
- #<lambda -0xf0a185e354afe4a> 1,815,264 36%
- let 284,064 5%
- if 284,064 5%
- progn 284,064 5%
setq 284,064 5%
+ if 1,208 0%
profiler-start 463 0%
Are these numbers as expected?
Sometimes, all of a sudden, regardless of what version of the function I
use, the memory
consumed by abbrev-suggest can be as low as 80,000 bytes. What have
happened then?
Something the GC does?
Thanks!
/Mathias
[-- Attachment #2: Type: text/html, Size: 9458 bytes --]
next prev parent reply other threads:[~2020-05-17 14:59 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-16 7:51 Abbrev suggestions - feedback appreciated Mathias Dahl
2017-09-16 8:46 ` Eli Zaretskii
2017-09-17 13:15 ` Mathias Dahl
2017-09-16 13:22 ` Stefan Monnier
2017-09-17 13:22 ` Mathias Dahl
2017-09-17 14:03 ` Mathias Dahl
2017-09-17 21:23 ` Stefan Monnier
2017-09-17 21:56 ` Mathias Dahl
2017-10-03 12:51 ` Kaushal Modi
2017-10-07 15:13 ` Mathias Dahl
2017-10-07 15:29 ` Stefan Monnier
2017-10-07 17:18 ` Mathias Dahl
2017-10-07 18:40 ` Mathias Dahl
2017-10-07 22:29 ` Ian Dunn
2017-10-07 22:44 ` Stefan Monnier
2017-10-08 16:38 ` Ian Dunn
2018-09-17 21:48 ` Mathias Dahl
2018-09-18 2:05 ` Stefan Monnier
2020-05-11 21:37 ` Mathias Dahl
2020-05-11 22:39 ` Mathias Dahl
2020-05-11 22:58 ` Stefan Monnier
2020-05-16 22:10 ` Mathias Dahl
2020-05-16 22:22 ` Mathias Dahl
2020-05-17 3:13 ` Stefan Monnier
2020-05-17 14:59 ` Mathias Dahl [this message]
2020-05-17 15:45 ` Eli Zaretskii
2020-05-17 18:43 ` Mathias Dahl
2020-05-17 21:20 ` Stefan Monnier
2020-05-18 22:00 ` Mathias Dahl
2020-06-04 20:14 ` Mathias Dahl
2017-10-07 22:40 ` Stefan Monnier
2017-10-08 15:28 ` Mathias Dahl
-- strict thread matches above, loose matches on Subject: below --
2017-10-08 8:15 Seweryn Kokot
2017-10-08 15:25 ` Mathias Dahl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABrcCQ4sPJPuEROVUoa6ifrkusXp3DnOoFH+Jy7TVzip1SkXpw@mail.gmail.com \
--to=mathias.dahl@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).