]> git.ipfire.org Git - thirdparty/vim.git/commit
patch 9.1.0704: inserting with a count is inefficient v9.1.0704
authorKen Takata <kentkt@csc.jp>
Sat, 31 Aug 2024 14:35:06 +0000 (16:35 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 31 Aug 2024 14:35:06 +0000 (16:35 +0200)
commit09b80d23cfae24fa13ef4f52b0ec90625839a6ab
tree79eef037d7966622734944e460ee396a27ad124d
parent7c8bbc6d28387e5c73f049663ace0c3829f9e128
patch 9.1.0704: inserting with a count is inefficient

Problem:  inserting with a count is inefficient
Solution: Disable calculation of the cursor position and topline, if a
          count has been used (Ken Takata)

Optimize insertion when using :normal 10000ix.

This patch optimizes the insertion with a large count (e.g. `:normal
10000ix`).

It seems that calculation of the cursor position for a long line is slow
and it takes O(n^2). Disable the calculation if not needed.

Before:
```
$ time ./vim --clean -c 'normal 10000ix' -cq!
real    0m1.879s
user    0m1.328s
sys     0m0.139s

$ time ./vim --clean -c 'normal 20000ix' -cq!
real    0m5.574s
user    0m5.421s
sys     0m0.093s

$ time ./vim --clean -c 'normal 40000ix' -cq!
real    0m23.588s
user    0m23.187s
sys     0m0.140s
```

After:
```
$ time ./vim --clean -c 'normal 10000ix' -cq!
real    0m0.187s
user    0m0.046s
sys     0m0.093s

$ time ./vim --clean -c 'normal 20000ix' -cq!
real    0m0.217s
user    0m0.046s
sys     0m0.108s

$ time ./vim --clean -c 'normal 40000ix' -cq!
real    0m0.278s
user    0m0.093s
sys     0m0.140s

$ time ./vim --clean -c 'normal 80000ix' -cq!
real    0m0.494s
user    0m0.311s
sys     0m0.140s

$ time ./vim --clean -c 'normal 160000ix' -cq!
real    0m1.302s
user    0m1.140s
sys     0m0.094s
```

closes: #15588

Signed-off-by: K.Takata <kentkt@csc.jp>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/edit.c
src/version.c