Skip to content

Commit 09b80d2

Browse files
k-takatachrisbra
authored andcommitted
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>
1 parent 7c8bbc6 commit 09b80d2

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/edit.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ edit(
512512
#ifdef FEAT_DIFF
513513
&& curwin->w_topfill == old_topfill
514514
#endif
515+
&& count <= 1
515516
)
516517
{
517518
mincol = curwin->w_wcol;
@@ -549,11 +550,13 @@ edit(
549550
}
550551

551552
// May need to adjust w_topline to show the cursor.
552-
update_topline();
553+
if (count <= 1)
554+
update_topline();
553555

554556
did_backspace = FALSE;
555557

556-
validate_cursor(); // may set must_redraw
558+
if (count <= 1)
559+
validate_cursor(); // may set must_redraw
557560

558561
/*
559562
* Redraw the display when no characters are waiting.
@@ -566,7 +569,8 @@ edit(
566569

567570
if (curwin->w_p_crb)
568571
do_check_cursorbind();
569-
update_curswant();
572+
if (count <= 1)
573+
update_curswant();
570574
old_topline = curwin->w_topline;
571575
#ifdef FEAT_DIFF
572576
old_topfill = curwin->w_topfill;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
704,
707709
/**/
708710
703,
709711
/**/

0 commit comments

Comments
 (0)