From 7086751c5e4eb3cfee0b98df0d3cedc8bff47d35 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 5 Aug 2019 17:42:41 -0400 Subject: vim-patch:8.1.1439: ga_grow(): 1.5x growth rate #10699 Problem: Json_encode() is very slow for large results. Solution: In the growarray use a growth of at least 50%. (Ken Takata, closes vim/vim#4461) https://github.com/vim/vim/commit/c47ed44be76a520ded90913099771999c8a79eeb --- src/nvim/garray.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 74fd9d89cb..1cfc2b6176 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -89,6 +89,14 @@ void ga_grow(garray_T *gap, int n) if (n < gap->ga_growsize) { n = gap->ga_growsize; } + + // A linear growth is very inefficient when the array grows big. This + // is a compromise between allocating memory that won't be used and too + // many copy operations. A factor of 1.5 seems reasonable. + if (n < gap->ga_len / 2) { + n = gap->ga_len / 2; + } + int new_maxlen = gap->ga_len + n; size_t new_size = (size_t)gap->ga_itemsize * (size_t)new_maxlen; -- cgit