[svn:parrot] r42062 - in trunk: src/pmc t/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sat Oct 24 01:31:41 UTC 2009


Author: bacek
Date: Sat Oct 24 01:31:40 2009
New Revision: 42062
URL: https://trac.parrot.org/parrot/changeset/42062

Log:
Use FixedSizeStorage in CallSignatureReturns for small amount of returns. Give us another ~1.5% of performance

Modified:
   trunk/src/pmc/callsignaturereturns.pmc
   trunk/t/pmc/callsignaturereturns.t

Modified: trunk/src/pmc/callsignaturereturns.pmc
==============================================================================
--- trunk/src/pmc/callsignaturereturns.pmc	Sat Oct 24 01:31:14 2009	(r42061)
+++ trunk/src/pmc/callsignaturereturns.pmc	Sat Oct 24 01:31:40 2009	(r42062)
@@ -37,6 +37,8 @@
 
 CallSignatureReturns will behave like CPointer with autocasting values.
 
+Up to 8 returns use FixedSizeAllocator. Switch to malloc/free after.
+
 =head2 Functions
 
 =over 4
@@ -67,10 +69,16 @@
 */
     VTABLE void destroy() {
         void    **values;
+        INTVAL    resize_threshold;
 
         GET_ATTR_values(INTERP, SELF, values);
-        if (values)
-            mem_sys_free(values);
+        GET_ATTR_resize_threshold(INTERP, SELF, resize_threshold);
+        if (values) {
+            if (resize_threshold == 8)
+                Parrot_gc_free_fixed_size_storage(INTERP, 8 * sizeof (void *), values);
+            else
+                mem_sys_free(values);
+        }
     }
 /*
 
@@ -91,7 +99,7 @@
 
         if (!values) {
             /* Empty. Allocate 8 elements (arbitary number) */
-            values = mem_allocate_n_zeroed_typed(8, void*);
+            values = (void **)Parrot_gc_allocate_fixed_size_storage(INTERP, 8 * sizeof (void *));
             SET_ATTR_values(INTERP, SELF, values);
             SET_ATTR_size(INTERP, SELF, size);
             SET_ATTR_resize_threshold(INTERP, SELF, 8);
@@ -101,7 +109,15 @@
             return;
         }
         else {
-            INTVAL  cur = resize_threshold;
+            INTVAL  cur        = resize_threshold;
+            void   *old_values;
+
+            /* Switch to system allocator */
+            if (cur == 8) {
+                old_values = values;
+                values = (void **) mem_allocate_n_typed(8, void *);
+                memcpy(values, old_values, 8 * sizeof(void *));
+            }
 
             if (cur < 8192)
                 cur = size < 2 * cur ? 2 * cur : size;

Modified: trunk/t/pmc/callsignaturereturns.t
==============================================================================
--- trunk/t/pmc/callsignaturereturns.t	Sat Oct 24 01:31:14 2009	(r42061)
+++ trunk/t/pmc/callsignaturereturns.t	Sat Oct 24 01:31:40 2009	(r42062)
@@ -22,6 +22,7 @@
     plan(1)
 
     instantiate()
+    switch_storage()
 .end
 
 
@@ -30,6 +31,21 @@
     ok(1, 'Instantiated CallSignatureReturns')
 .end
 
+# Check that internal switching of storage works.
+.sub switch_storage
+    .local pmc r
+    (r :slurpy) = 'return_many'()
+    sweep 1
+    $S0 = join '', r
+    is($S0, "This is very long string to return as characters", "Internal storage switched")
+.end
+
+.sub return_many
+    .local pmc res
+    res = split '', "This is very long string to return as characters"
+    .return (res :flat)
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100


More information about the parrot-commits mailing list