Complexity analysis to algorithms used in collect

This commit is contained in:
valtermiari 2023-03-22 12:02:16 +01:00
parent 87dc0fef2d
commit 8414703fe6
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,4 @@
define void @f() gc "gc" {
entry:
ret void
}

View file

@ -184,6 +184,10 @@ namespace GC
* If a chunk is marked it is removed from the worklist, since it's no longer of * If a chunk is marked it is removed from the worklist, since it's no longer of
* concern for this method. * concern for this method.
* *
* Time complexity: 0(N^2 * log(N)) as upper bound.
* Where N is either the size of the worklist or the size of
* the stack frame, depending on which is the largest.
*
* @param start Pointer to the start of the stack frame. * @param start Pointer to the start of the stack frame.
* @param end Pointer to the end of the stack frame. * @param end Pointer to the end of the stack frame.
* @param worklist The currently allocated chunks, which haven't been marked. * @param worklist The currently allocated chunks, which haven't been marked.
@ -238,6 +242,10 @@ namespace GC
* Sweeps the heap, unmarks the marked chunks for the next cycle, * Sweeps the heap, unmarks the marked chunks for the next cycle,
* adds the unmarked nodes to the list of freed chunks; to be freed. * adds the unmarked nodes to the list of freed chunks; to be freed.
* *
* Time complexity: O(N^2), where N is the number of allocated chunks.
* It is quadratic, in the worst case,
* since each call to erase() is linear.
*
* @param heap Pointer to the heap singleton instance. * @param heap Pointer to the heap singleton instance.
*/ */
void Heap::sweep(Heap *heap) void Heap::sweep(Heap *heap)
@ -273,6 +281,10 @@ namespace GC
* amount of free chunks, delete the free chunks to * amount of free chunks, delete the free chunks to
* avoid cluttering. * avoid cluttering.
* *
* Time complexity: O(N^2), where N is the freed chunks.
* If free_overlap() is called, it runs in O(N^2),
* otherwise O(N).
*
* @param heap Heap singleton instance, only for avoiding * @param heap Heap singleton instance, only for avoiding
* redundant calls to the singleton get * redundant calls to the singleton get
*/ */
@ -304,11 +316,15 @@ namespace GC
* and removes overlapping chunks while prioritizing * and removes overlapping chunks while prioritizing
* the chunks at lower addresses. * the chunks at lower addresses.
* *
* Time complexity: O(N^2), where N is the number of freed chunks.
* At each iteration get_at() is called, which is linear.
*
* @param heap Heap singleton instance, only for avoiding * @param heap Heap singleton instance, only for avoiding
* redundant calls to the singleton get * redundant calls to the singleton get
* *
* @note Maybe this should be changed to prioritizing * @note Maybe this should be changed to prioritizing
* larger chunks. * larger chunks. Should remove get_at() to indexing,
* since that's constant.
*/ */
void Heap::free_overlap(Heap *heap) // borde göra en record(ChunkFreed) på onödiga chunks void Heap::free_overlap(Heap *heap) // borde göra en record(ChunkFreed) på onödiga chunks
{ {