[前][次][番号順一覧][スレッド一覧]

ruby-changes:34875

From: normal <ko1@a...>
Date: Sat, 26 Jul 2014 16:57:51 +0900 (JST)
Subject: [ruby-changes:34875] normal:r46958 (trunk): struct iseq_compile_data_storage: 16 bytes (from 32) overhead

normal	2014-07-26 16:57:44 +0900 (Sat, 26 Jul 2014)

  New Revision: 46958

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46958

  Log:
    struct iseq_compile_data_storage: 16 bytes (from 32) overhead
    
    This reduces the iseq_compile_data_storage header from 32 to 16
    bytes on 64-bit systems.
    
    pos and size fields cannot exceed 32-bit sizes due to stack size
    limits.  Using a flexible array for the buffer also saves us 8
    bytes of pointer overhead.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/iseq.c
    trunk/iseq.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46957)
+++ ChangeLog	(revision 46958)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jul 26 16:55:18 2014  Eric Wong  <e@8...>
+
+	* iseq.h (struct iseq_compile_data_storage): reduce overhead
+	  to 16 bytes (from 32) on 64-bit
+
 Sat Jul 26 16:28:06 2014  Eric Wong  <e@8...>
 
 	* vm_core.h (struct rb_iseq_struct): reduce to 280 bytes
Index: iseq.c
===================================================================
--- iseq.c	(revision 46957)
+++ iseq.c	(revision 46958)
@@ -153,7 +153,7 @@ iseq_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/iseq.c#L153
 
 		cur = iseq->compile_data->storage_head;
 		while (cur) {
-		    size += cur->size + sizeof(struct iseq_compile_data_storage);
+		    size += cur->size + SIZEOF_ISEQ_COMPILE_DATA_STORAGE;
 		    cur = cur->next;
 		}
 		size += sizeof(struct iseq_compile_data);
@@ -293,15 +293,13 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L293
     iseq->compile_data->storage_head = iseq->compile_data->storage_current =
       (struct iseq_compile_data_storage *)
 	ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
-		sizeof(struct iseq_compile_data_storage));
+		SIZEOF_ISEQ_COMPILE_DATA_STORAGE);
 
     RB_OBJ_WRITE(iseq->self, &iseq->compile_data->catch_table_ary, rb_ary_new());
     iseq->compile_data->storage_head->pos = 0;
     iseq->compile_data->storage_head->next = 0;
     iseq->compile_data->storage_head->size =
       INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
-    iseq->compile_data->storage_head->buff =
-      (char *)(&iseq->compile_data->storage_head->buff + 1);
     iseq->compile_data->option = option;
     iseq->compile_data->last_coverable_line = -1;
 
Index: iseq.h
===================================================================
--- iseq.h	(revision 46957)
+++ iseq.h	(revision 46958)
@@ -88,11 +88,15 @@ iseq_catch_table_bytes(int n) https://github.com/ruby/ruby/blob/trunk/iseq.h#L88
 
 struct iseq_compile_data_storage {
     struct iseq_compile_data_storage *next;
-    unsigned long pos;
-    unsigned long size;
-    char *buff;
+    unsigned int pos;
+    unsigned int size;
+    char buff[1]; /* flexible array */
 };
 
+/* account for flexible array */
+#define SIZEOF_ISEQ_COMPILE_DATA_STORAGE \
+    (sizeof(struct iseq_compile_data_storage) - 1)
+
 struct iseq_compile_data {
     /* GC is needed */
     const VALUE err_info;
Index: compile.c
===================================================================
--- compile.c	(revision 46957)
+++ compile.c	(revision 46958)
@@ -604,13 +604,11 @@ compile_data_alloc(rb_iseq_t *iseq, size https://github.com/ruby/ruby/blob/trunk/compile.c#L604
 	    goto retry;
 	}
 	storage->next = (void *)ALLOC_N(char, alloc_size +
-					sizeof(struct
-					       iseq_compile_data_storage));
+					SIZEOF_ISEQ_COMPILE_DATA_STORAGE);
 	storage = iseq->compile_data->storage_current = storage->next;
 	storage->next = 0;
 	storage->pos = 0;
 	storage->size = alloc_size;
-	storage->buff = (char *)(&storage->buff + 1);
     }
 
     ptr = (void *)&storage->buff[storage->pos];

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]