-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The library uses a lot of stack #13
Comments
Ok, this is possible. Public keys of Classic McEliece are huge and various operations are applied. Fundamentally I preferred to use the stack for allocation over the heap. If there is some unnecessary copy operation somewhere, I will gladly fix it. It is difficult to fix it without knowing the location though. |
Probably at some point it would be nice to look at temporary buffers that are used by keygen,encaps,decaps and see if there are some that are huge and can be reduced. |
I tried to run https://crates.io/crates/cargo-call-stack on this crate. But it failed. But using something like that to see which functions require a lot of stack could be very helpful in finding out where the lowest hanging fruits are. |
I actually tried the same project yesterday, got a bit further by using the musl target, but there are a lot of unhandled llvm intrinsics atm. When I get the time ill try a patched version that just assumes all llvm intrinsics lower to machine code. |
FTR: My account @prokls is inactive since I left university quite some time ago. I am going to use my private account @meisterluk now to contribute. I did a code review for the current HEAD and inserted the highest numbers for the configuration with the largest keys. I was able to find the following (larger) stack allocations:
Additional attention must be spent on:
Then the following conclusions can be made:
I changed |
This is apparently not as bad as it used to be. Maybe this is even a non-issue? I have not analyzed this in a long time. I think we have lowered the amount of stack we assign the special CME thread at some point. But we still run it in a separate thread, so we don't have to rely on default stack sizes. Yours seems to be 8 MiB, but we can't rely on that being the case everywhere. The code has to run fine on mobile etc for us as well. This is our current workaround for the stack problem. But the comment seems to indicate that we no longer know if this actually is a problem 🙃 EDIT: We of course run it in a separate thread in order to make it not block the async runtime. This is a way to offload the computation. |
When using the library in the variant with the largest public key (namely mceliece8192128), the stack allocation amounts to 1,703,936 bytes. This is 20% of the maximum admissible stack size of my system. This high stack consumption is a problem on several systems. Thus, I propose to allocate this huge array on the heap. Context: issue #13 #13
We have noticed that for the larger key sizes that the library supports, we need to run the functions in a thread with increased stack size. Even if we pass in heap allocated buffers for the key out parameters. My guess is that the library stores the public key on the stack somewhere internally. We have not looked at the code. But it would be great if the caller could somehow tell the library to use the heap more, so it can run in threads with default stack sizes.
This is somewhat related to #12, where we also need a way for the caller to control how the library handles memory buffers.
The text was updated successfully, but these errors were encountered: