Skip to content

Commit c47ed44

Browse files
committed
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)
1 parent 815b76b commit c47ed44

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/misc2.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,13 @@ ga_grow(garray_T *gap, int n)
20572057
{
20582058
if (n < gap->ga_growsize)
20592059
n = gap->ga_growsize;
2060+
2061+
// A linear growth is very inefficient when the array grows big. This
2062+
// is a compromise between allocating memory that won't be used and too
2063+
// many copy operations. A factor of 1.5 seems reasonable.
2064+
if (n < gap->ga_len / 2)
2065+
n = gap->ga_len / 2;
2066+
20602067
new_len = gap->ga_itemsize * (gap->ga_len + n);
20612068
pp = vim_realloc(gap->ga_data, new_len);
20622069
if (pp == NULL)

src/version.c

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

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1439,
770772
/**/
771773
1438,
772774
/**/

0 commit comments

Comments
 (0)