hnes / libaco

A blazing fast and lightweight C asymmetric coroutine library 💎 ⛅🚀⛅🌞
https://libaco.org
Apache License 2.0
3.49k stars 392 forks source link

is 120byte the lowest we can have? possible to lower this? #50

Open superdolt opened 2 years ago

superdolt commented 2 years ago

120byte sounds like a lot. possible to use ideas from here to lower it? https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

40bytes possible?

hnes commented 2 years ago

120byte sounds like a lot.

Do you mean the size of the copied memory during coroutine switch (in the shared stack mode)?

You may refer to the source of the test_aco_benchmark.c:

// ...

void co_fp_stksz_40(){
    int ip[8];
    memset(ip, 1, sizeof(ip));
    while(1){
        aco_yield();
    }
    aco_exit();
}

void co_fp_stksz_24(){
    int ip[4];
    memset(ip, 1, sizeof(ip));
    while(1){
        aco_yield();
    }
    aco_exit();
}

void co_fp_stksz_8(){
    while(1){
        aco_yield();
    }
    aco_exit();
}

The copy size is totally determined by the actual stack size when the coroutine is doing the coroutine switch stuff. It could even be zero if you write your coroutine function elaborately enough, in assembly language for example.