Skip to content

optimize gcContains function #118

@tiancaiamao

Description

@tiancaiamao

cora/src/gc.c

Lines 319 to 337 in 24c26bb

static struct heapArena *
gcContains(struct GC *gc, void *p) {
struct heapArena *h = gc->heap;
while (h != NULL) {
if (heapArenaContains(h, p)) {
return h;
}
h = h->next;
}
h = gc->large;
while (h != NULL) {
if (heapArenaContains(h, p)) {
return h;
}
h = h->next;
}
return NULL;
}

Currently the gcContains function is a O(n) operation, if the each heap arean is 64M, and the process memory usage is 8G
Then there will be 128 heap arenas ... it still cost too much.

We can organize the heap arenas as ordered or as tree struct, to reduce the cost to O(logN)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions