0
0
mirror of https://github.com/vim/vim.git synced 2025-10-24 08:54:47 -04:00
Files
vim/src/Make_ami.mak
Girish Palya 7e0df5eee9 patch 9.1.1627: fuzzy matching can be improved
Problem:  fuzzy-matching can be improved
Solution: Implement a better fuzzy matching algorithm
          (Girish Palya)

Replace fuzzy matching algorithm with improved fzy-based implementation

The
[current](https://www.forrestthewoods.com/blog/reverse_engineering_sublime_texts_fuzzy_match/)
fuzzy matching algorithm has several accuracy issues:

* It struggles with CamelCase
* It fails to prioritize matches at the beginning of strings, often
  ranking middle matches higher.

After evaluating alternatives (see my comments
[here](https://github.com/vim/vim/issues/17531#issuecomment-3112046897)
and
[here](https://github.com/vim/vim/issues/17531#issuecomment-3121593900)),
I chose to adopt the [fzy](https://github.com/jhawthorn/fzy) algorithm,
which:

* Resolves the aforementioned issues.
* Performs better.

Implementation details

This version is based on the original fzy
[algorithm](https://github.com/jhawthorn/fzy/blob/master/src/match.c),
with one key enhancement: **multibyte character support**.

* The original implementation supports only ASCII.
* This patch replaces ascii lookup tables with function calls, making it
  compatible with multibyte character sets.
* Core logic (`match_row()` and `match_positions()`) remains faithful to
  the original, but now operates on codepoints rather than single-byte
  characters.

Performance

Tested against a dataset of **90,000 Linux kernel filenames**. Results
(in milliseconds) show a **\~2x performance improvement** over the
current fuzzy matching algorithm.

```
Search String            Current Algo    FZY Algo
-------------------------------------------------
init                          131.759    66.916
main                          83.688     40.861
sig                           98.348     39.699
index                         109.222    30.738
ab                            72.222     44.357
cd                            83.036     54.739
a                             58.94      62.242
b                             43.612     43.442
c                             64.39      67.442
k                             40.585     36.371
z                             34.708     22.781
w                             38.033     30.109
cpa                           82.596     38.116
arz                           84.251     23.964
zzzz                          35.823     22.75
dimag                         110.686    29.646
xa                            43.188     29.199
nha                           73.953     31.001
nedax                         94.775     29.568
dbue                          79.846     25.902
fp                            46.826     31.641
tr                            90.951     55.883
kw                            38.875     23.194
rp                            101.575    55.775
kkkkkkkkkkkkkkkkkkkkkkkkkkkkk 48.519     30.921
```

```vim
vim9script

var haystack = readfile('/Users/gp/linux.files')

var needles = ['init', 'main', 'sig', 'index', 'ab', 'cd', 'a', 'b',
'c', 'k',
    'z', 'w', 'cpa', 'arz', 'zzzz', 'dimag', 'xa', 'nha', 'nedax',
'dbue',
    'fp', 'tr', 'kw', 'rp', 'kkkkkkkkkkkkkkkkkkkkkkkkkkkkk']
for needle in needles
    var start = reltime()
    var tmp = matchfuzzy(haystack, needle)
    echom $'{needle}' (start->reltime()->reltimefloat() * 1000)
endfor
```

Additional changes

* Removed the "camelcase" option from both matchfuzzy() and
  matchfuzzypos(), as it's now obsolete with the improved algorithm.

related: neovim/neovim#34101
fixes #17531
closes: #17900

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-08-12 22:22:52 +02:00

209 lines
2.8 KiB
Makefile

#
# Makefile for AROS, AmigaOS4 and MorphOS.
#
BIN = vim
CC ?= gcc
LD = $(CC)
UNM ?= $(shell uname)
DEBUG ?= no
BUILD ?= huge
CFLAGS = -c -O3
# Common compiler flags
CFLAGS += \
-DNO_ARP \
-DUSE_TMPNAM \
-DHAVE_STDARG_H \
-DHAVE_TGETENT \
-DHAVE_TERMCAP \
-DNEW_SHELLSIZE \
-I proto \
-Wno-attributes \
-Wextra
# Vim 'huge' build
ifeq ($(BUILD),huge)
CFLAGS += \
-DFEAT_BROWSE \
-DFEAT_MOUSE \
-DFEAT_HUGE
else
# Vim 'normal' build
ifeq ($(BUILD),normal)
CFLAGS +=\
-DFEAT_BROWSE \
-DFEAT_MOUSE \
-DFEAT_NORMAL
else
# Vim 'small' build - now an alias for 'tiny'
ifeq ($(BUILD),small)
CFLAGS += -DFEAT_TINY
else
# Vim 'tiny' build
ifeq ($(BUILD),tiny)
CFLAGS += -DFEAT_TINY
endif
endif
endif
endif
endif
# OS specific compiler flags
ifeq ($(UNM),AmigaOS)
LDFLAGS = -lauto
CFLAGS += -DHAVE_FSYNC -D__USE_INLINE__
else
ifeq ($(UNM),AROS)
LDFLAGS = -DHAVE_FSYNC -ldebug
else
ifeq ($(UNM),MorphOS)
CFLAGS += -noixemul
LDFLAGS = -ldebug -lm -noixemul
endif
endif
endif
# Patch level used for Amiga style version string
ifdef PATCHLEVEL
CFLAGS += -DPATCHLEVEL=\"$(PATCHLEVEL)\"
endif
# Common sources
SRC += \
alloc.c \
arabic.c \
arglist.c \
autocmd.c \
beval.c \
blob.c \
blowfish.c \
buffer.c \
bufwrite.c \
change.c \
charset.c \
cindent.c \
clientserver.c \
clipboard.c \
cmdhist.c \
cmdexpand.c \
crypt.c \
crypt_zip.c \
debugger.c \
dict.c \
diff.c \
digraph.c \
drawline.c \
drawscreen.c \
edit.c \
eval.c \
evalbuffer.c \
evalfunc.c \
evalvars.c \
evalwindow.c \
ex_cmds.c \
ex_cmds2.c \
ex_docmd.c \
ex_eval.c \
ex_getln.c \
fileio.c \
filepath.c \
findfile.c \
float.c \
fold.c \
fuzzy.c \
getchar.c \
gc.c \
hardcopy.c \
hashtab.c \
help.c \
highlight.c \
if_cscope.c \
indent.c \
insexpand.c \
json.c \
linematch.c\
list.c \
locale.c \
logfile.c \
main.c \
mark.c \
map.c \
match.c \
mbyte.c \
memfile.c \
memline.c \
menu.c \
message.c \
misc1.c \
misc2.c \
mouse.c \
move.c \
normal.c \
ops.c \
option.c \
optionstr.c \
os_amiga.c \
popupmenu.c \
popupwin.c \
quickfix.c \
regexp.c \
register.c \
screen.c \
scriptfile.c \
search.c \
session.c \
sha256.c \
sign.c \
spell.c \
spellfile.c \
spellsuggest.c \
strings.c \
syntax.c \
tag.c \
tabpanel.c \
term.c \
termlib.c \
testing.c \
textformat.c \
textobject.c \
textprop.c \
time.c \
tuple.c \
typval.c \
ui.c \
undo.c \
usercmd.c \
userfunc.c \
version.c \
viminfo.c \
vim9class.c \
vim9cmds.c \
vim9compile.c \
vim9execute.c \
vim9expr.c \
vim9generics.c \
vim9instr.c \
vim9script.c \
vim9type.c \
window.c \
xdiff/xdiffi.c \
xdiff/xemit.c \
xdiff/xhistogram.c \
xdiff/xpatience.c \
xdiff/xprepare.c \
xdiff/xutils.c
OBJ = $(SRC:.c=.o)
# Build everything - Ignoring header dependencies.
$(BIN): $(OBJ)
${LD} -o $(BIN) $(OBJ) $(LDFLAGS)
# Clean up
.PHONY: clean
clean:
$(RM) -fv $(OBJ) $(BIN)