Mercurial > vim
changeset 16876:cdca5f577c36 v8.1.1439
patch 8.1.1439: json_encode() is very slow for large results
commit https://github.com/vim/vim/commit/c47ed44be76a520ded90913099771999c8a79eeb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 1 14:36:26 2019 +0200
patch 8.1.1439: json_encode() is very slow for large results
Problem: Json_encode() is very slow for large results.
Solution: In the growarray use a growth of at least 50%. (Ken Takata,
closes #4461)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 01 Jun 2019 14:45:04 +0200 |
parents | df19064e8d01 |
children | 48ee9f2e994c |
files | src/misc2.c src/version.c |
diffstat | 2 files changed, 9 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/misc2.c +++ b/src/misc2.c @@ -2057,6 +2057,13 @@ 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; + new_len = gap->ga_itemsize * (gap->ga_len + n); pp = vim_realloc(gap->ga_data, new_len); if (pp == NULL)