1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2014-07-26 07:57:44 +00:00
parent a9c7629ece
commit 36b476cd1e
4 changed files with 15 additions and 10 deletions

View file

@ -1,3 +1,8 @@
Sat Jul 26 16:55:18 2014 Eric Wong <e@80x24.org>
* 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@80x24.org> Sat Jul 26 16:28:06 2014 Eric Wong <e@80x24.org>
* vm_core.h (struct rb_iseq_struct): reduce to 280 bytes * vm_core.h (struct rb_iseq_struct): reduce to 280 bytes

View file

@ -604,13 +604,11 @@ compile_data_alloc(rb_iseq_t *iseq, size_t size)
goto retry; goto retry;
} }
storage->next = (void *)ALLOC_N(char, alloc_size + storage->next = (void *)ALLOC_N(char, alloc_size +
sizeof(struct SIZEOF_ISEQ_COMPILE_DATA_STORAGE);
iseq_compile_data_storage));
storage = iseq->compile_data->storage_current = storage->next; storage = iseq->compile_data->storage_current = storage->next;
storage->next = 0; storage->next = 0;
storage->pos = 0; storage->pos = 0;
storage->size = alloc_size; storage->size = alloc_size;
storage->buff = (char *)(&storage->buff + 1);
} }
ptr = (void *)&storage->buff[storage->pos]; ptr = (void *)&storage->buff[storage->pos];

6
iseq.c
View file

@ -153,7 +153,7 @@ iseq_memsize(const void *ptr)
cur = iseq->compile_data->storage_head; cur = iseq->compile_data->storage_head;
while (cur) { while (cur) {
size += cur->size + sizeof(struct iseq_compile_data_storage); size += cur->size + SIZEOF_ISEQ_COMPILE_DATA_STORAGE;
cur = cur->next; cur = cur->next;
} }
size += sizeof(struct iseq_compile_data); size += sizeof(struct iseq_compile_data);
@ -293,15 +293,13 @@ prepare_iseq_build(rb_iseq_t *iseq,
iseq->compile_data->storage_head = iseq->compile_data->storage_current = iseq->compile_data->storage_head = iseq->compile_data->storage_current =
(struct iseq_compile_data_storage *) (struct iseq_compile_data_storage *)
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE + 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()); 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->pos = 0;
iseq->compile_data->storage_head->next = 0; iseq->compile_data->storage_head->next = 0;
iseq->compile_data->storage_head->size = iseq->compile_data->storage_head->size =
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_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->option = option;
iseq->compile_data->last_coverable_line = -1; iseq->compile_data->last_coverable_line = -1;

10
iseq.h
View file

@ -88,11 +88,15 @@ iseq_catch_table_bytes(int n)
struct iseq_compile_data_storage { struct iseq_compile_data_storage {
struct iseq_compile_data_storage *next; struct iseq_compile_data_storage *next;
unsigned long pos; unsigned int pos;
unsigned long size; unsigned int size;
char *buff; 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 { struct iseq_compile_data {
/* GC is needed */ /* GC is needed */
const VALUE err_info; const VALUE err_info;