Skip to content

Commit b9b9b3e

Browse files
committed
rt: Set the initial obstack size to 128 bytes
Double the size on each allocation
1 parent b3eb9a0 commit b9b9b3e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/rt/rust_obstack.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#undef DPRINT
2121
#define DPRINT(fmt, ...)
2222

23-
//const size_t DEFAULT_CHUNK_SIZE = 4096;
24-
const size_t DEFAULT_CHUNK_SIZE = 500000;
23+
const size_t DEFAULT_CHUNK_SIZE = 128;
24+
const size_t MAX_CHUNK_SIZE = (1024*64);
2525
const size_t DEFAULT_ALIGNMENT = 16;
2626

2727
// A single type-tagged allocation in a chunk.
@@ -42,7 +42,6 @@ rust_obstack_chunk::alloc(size_t len, type_desc *tydesc) {
4242

4343
if (sizeof(rust_obstack_alloc) + len > size - alen) {
4444
DPRINT("Not enough space, len=%lu!\n", len);
45-
assert(0); // FIXME
4645
return NULL; // Not enough space.
4746
}
4847

@@ -70,9 +69,15 @@ rust_obstack_chunk::mark() {
7069
// Allocates the given number of bytes in a new chunk.
7170
void *
7271
rust_obstack::alloc_new(size_t len, type_desc *tydesc) {
72+
size_t default_chunk_size = DEFAULT_CHUNK_SIZE;
73+
if (chunk) {
74+
default_chunk_size = std::min(chunk->size * 2, MAX_CHUNK_SIZE);
75+
}
76+
7377
size_t chunk_size = std::max(sizeof(rust_obstack_alloc) + len,
74-
DEFAULT_CHUNK_SIZE);
75-
void *ptr = task->malloc(sizeof(chunk) + chunk_size, "obstack");
78+
default_chunk_size);
79+
void *ptr = task->malloc(sizeof(rust_obstack_chunk) + chunk_size,
80+
"obstack");
7681
DPRINT("making new chunk at %p, len %lu\n", ptr, chunk_size);
7782
chunk = new(ptr) rust_obstack_chunk(chunk, chunk_size);
7883
return chunk->alloc(len, tydesc);

0 commit comments

Comments
 (0)