From: zimoun <zimon.toutoune@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 45893@debbugs.gnu.org
Subject: [bug#45893] Hint for package name: full matrix iteration
Date: Wed, 20 Jan 2021 10:49:47 +0100 [thread overview]
Message-ID: <86ft2w7xac.fsf@gmail.com> (raw)
In-Reply-To: <86o8hk8olh.fsf@gmail.com>
Hi,
On Wed, 20 Jan 2021 at 00:59, zimoun <zimon.toutoune@gmail.com> wrote:
> However, the first improvement is to speed up ’string-distance’. Well,
> the naive recursive implementation is well-known to be really slow.
For the interested reader, the patch implements the naive recursion
version. And just to compare, I have quickly compared to the iterative
with full matrix. See [1].
Roughly speaking, it is a factor of 5x.
--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,time (define x (read-the-cache "macs-mgit"))
;; 3.425513s real time, 4.524607s run time. 1.619604s spent in GC.
scheme@(guix-user)> ,time (define x (compute-distance2 "macs-mgit"))
;; 0.870167s real time, 1.056089s run time. 0.271307s spent in GC.
scheme@(guix-user)> ,time (define x (compute-distance "macs-mgit"))
;; 3.637917s real time, 5.601863s run time. 2.847500s spent in GC.
--8<---------------cut here---------------end--------------->8---
The naive recursion version seems fast enough for options and commands
–– because there are few. The key advantage of recursion implementation
is the readibility, IMHO. Compare with the iteration with full matrix
below.
I am in favor to merge this naive recursion version for now. And
postpone improvements. Because to be competitive for package hints,
instead of plain “edit distance“ which scales poorly, there is 2
directions:
- implement ’string-distance’ at the C level (in the standard library?)
- pre-process the package names at package cache build time; with
suffix tree or n-gram or <name-it> –– in the scope of “guix search”
improvements.
Both are piece of works and I am not convinced the package name hint is
worth.
Cheers,
simon
1: <https://en.wikipedia.org/wiki/Levenshtein_distance#Computing_Levenshtein_distance>
--8<---------------cut here---------------start------------->8---
(define (edit-distance s1 s2)
(let* ((as (string->list s1))
(bs (string->list s2))
(s (list->vector as))
(t (list->vector bs))
(m (length as))
(n (length bs))
(d (make-typed-array 'u32 0 (1+ m) (1+ n))))
(do ((i 1 (1+ i))) ((> i m))
(array-set! d i i 0))
(do ((j 1 (1+ j))) ((> j n))
(array-set! d j 0 j))
(do ((j 1 (1+ j))) ((> j n))
(do ((i 1 (1+ i))) ((> i m))
(let* ((c1 (vector-ref s (1- i)))
(c2 (vector-ref t (1- j)))
(cost (if (char=? c1 c2)
0 1))
(deletion (1+ (array-ref d (1- i) j)))
(insertion (1+ (array-ref d i (1- j))))
(substitution (+ cost
(array-ref d (1- i) (1- j))))
(v (min deletion
insertion
substitution)))
(array-set! d v i j))))
(array-ref d m n)))
--8<---------------cut here---------------end--------------->8---
next prev parent reply other threads:[~2021-01-20 9:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 16:37 [bug#45893] [PATCH 0/2] DRAFT: Hint for options zimoun
2021-01-15 16:39 ` [bug#45893] [PATCH 1/2] scripts: search, show: Replace 'args-fold*' by 'parse-command-line' zimoun
2021-01-15 16:39 ` [bug#45893] [PATCH 2/2] guix: scripts: Add hint for option typo zimoun
2021-01-19 17:20 ` [bug#45893] [PATCH 0/2] DRAFT: Hint for options Ludovic Courtès
2021-01-19 17:35 ` zimoun
2021-01-16 0:09 ` [bug#45893] [PATCH v2 0/3] DRAFT: Hint command line typo zimoun
2021-01-16 0:26 ` [bug#45893] [PATCH v2 1/3] scripts: search, show: Replace 'args-fold*' by 'parse-command-line' zimoun
2021-01-16 0:26 ` [bug#45893] [PATCH v2 2/3] guix: scripts: Add hint for option typo zimoun
2021-01-19 17:31 ` [bug#45893] [PATCH 0/2] DRAFT: Hint for options Ludovic Courtès
2021-01-16 0:26 ` [bug#45893] [PATCH v2 3/3] ui: Add command hint zimoun
2021-01-19 17:38 ` [bug#45893] [PATCH 0/2] DRAFT: Hint for options Ludovic Courtès
2021-01-19 18:01 ` zimoun
2021-01-26 20:53 ` Ludovic Courtès
2021-01-26 21:27 ` zimoun
2021-01-19 23:59 ` [bug#45893] Hint for package name: too slow! zimoun
2021-01-20 9:49 ` zimoun [this message]
2021-01-26 21:00 ` [bug#45893] [PATCH 0/2] DRAFT: Hint for options Ludovic Courtès
2021-01-26 21:44 ` zimoun
2021-01-27 22:09 ` Ludovic Courtès
2021-01-19 21:28 ` [bug#45893] [PATCH v3 1/3] utils: Add string distance zimoun
2021-01-19 21:28 ` [bug#45893] [PATCH v3 2/3] guix: scripts: Add hint for option typo zimoun
2021-01-19 21:28 ` [bug#45893] [PATCH v3 3/3] ui: Add hint for command typo zimoun
2021-01-26 21:18 ` [bug#45893] [PATCH 0/2] DRAFT: Hint for options Ludovic Courtès
2021-01-26 21:20 ` Ludovic Courtès
2021-01-26 22:05 ` zimoun
2021-02-03 11:28 ` bug#45893: " Ludovic Courtès
2021-02-03 12:15 ` [bug#45893] " zimoun
[not found] ` <YBxQxSO57N4kV4N0@jasmine.lan>
[not found] ` <86tuqrbjxr.fsf@gmail.com>
2021-02-04 23:08 ` [bug#45893] Typo helper doesn't always know which command is missing zimoun
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://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86ft2w7xac.fsf@gmail.com \
--to=zimon.toutoune@gmail.com \
--cc=45893@debbugs.gnu.org \
--cc=ludo@gnu.org \
/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/guix.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).