Lichen

Changeset

882:f84970ad4040
2019-01-28 Paul Boddie raw files shortlog changelog graph Test performance with the allocation of opaque blocks containing many instances. This improves performance considerably, but the float instances are never reclaimed. Finding a way to expose the instances as they are issued would make this approach sustainable. float-preallocation
templates/native/float.c (file)
     1.1 --- a/templates/native/float.c	Sun Jan 27 14:11:25 2019 +0100
     1.2 +++ b/templates/native/float.c	Mon Jan 28 21:16:56 2019 +0100
     1.3 @@ -30,26 +30,16 @@
     1.4  
     1.5  /* A table of preallocated float instances. */
     1.6  
     1.7 -#define NUM_PREALLOCATED 1000
     1.8 +#define NUM_PREALLOCATED 10000
     1.9  
    1.10 -__ref preallocated_floats[NUM_PREALLOCATED];
    1.11 -
    1.12 +static __ref preallocated_floats;
    1.13  static int floats_left = 0;
    1.14  
    1.15  /* Preallocate some float instances. */
    1.16  
    1.17  static void preallocate_floats()
    1.18  {
    1.19 -    int i;
    1.20 -
    1.21 -    for (i = 0; i < NUM_PREALLOCATED; i++)
    1.22 -    {
    1.23 -        /* Allocate a float for each table entry. */
    1.24 -
    1.25 -        preallocated_floats[i] = \
    1.26 -            __ALLOCATEIM(1, __INSTANCESIZE(__builtins___float_float));
    1.27 -    }
    1.28 -
    1.29 +    preallocated_floats = __ALLOCATEIM(NUM_PREALLOCATED, __INSTANCESIZE(__builtins___float_float));
    1.30      floats_left = NUM_PREALLOCATED;
    1.31  }
    1.32  
    1.33 @@ -62,7 +52,7 @@
    1.34          preallocate_floats();
    1.35  
    1.36      floats_left--;
    1.37 -    obj = preallocated_floats[floats_left];
    1.38 +    obj = preallocated_floats;
    1.39  
    1.40      /* Initialise the instance. */
    1.41  
    1.42 @@ -74,6 +64,10 @@
    1.43      attr = __ATTRVALUE(obj);
    1.44      __set_trailing_data(attr, __builtins___float_float, n);
    1.45  
    1.46 +    /* Reference the next float. */
    1.47 +
    1.48 +    preallocated_floats = (__ref) ((char *) preallocated_floats + __INSTANCESIZE(__builtins___float_float));
    1.49 +
    1.50      return attr;
    1.51  }
    1.52