-
Notifications
You must be signed in to change notification settings - Fork 112
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
Consider offering an API similar to copyless #10
Comments
Don't have the time at this very moment, but it certainly seems worth considering! |
If I were to write a PR with such an API, would you be interested in reviewing and maintaining it as part of the bumpalo crate? |
Probably? My concerns are basically:
Those are the things that I would look for when investigating copyless and its API. Maybe you can help do some of that investigation before jumping straight to a PR? |
I've played around with it for a bit using three tests on release: allocating a large array, a large struct and a large enum. All of these have been defined to be too large to keep on the stack without causing a panic because of stack overflow. I have found many good solutions that keep most of these scenarios off the stack, thus avoiding the panic. However I have not yet been able to find a solution that passes all three tests. Would you still be interested in an API that is not guaranteed -- and indeed have known failure modes? |
By tweaking the code a bit, I managed to find a version that passes all of my tests. I would consider it good enough for my own uses. I am still of the opinion that it is impossible to guarantee the optimization without language support such as something similar to placement new . If we want an API that is guaranteed to work, we should return a My implementation adds a single new method If you are still interested let me know, and I will prepare it for a pull request. |
Agreed, that it can't be guaranteed without changes to the language. I was hoping that we could do a best-effort solution where we run
This sounds great, exactly the kind of light maintenance burden I was hoping for.
With some way to (at least manually) verify whether a change takes us off LLVM's happy path or not (either a test or a script I could run manually to check) I would love to merge this functionality. |
My current implementation has a few tests that causes
I'll prepare the PR then. |
The copyless crate allows one to allocate a large struct on the heap without first creating it on the stack and then copying it. One should be able to do this with bumpalo too.
If you try to run this code, it will cause a stack overflow exception (even though we want the data on the heap):
The copyless crate solves this by using on the fact that llvm seems to be able to optimize
x = FOO; memcpy(ptr, &x, sizeof(x));
into*ptr = FOO
.On the other hand, llvm does not seem to be able to optimize
x = FOO; ptr = alloc(sizeof(x)); memcpy(ptr, &x, sizeof(x));
in the same way, and instead relies on the stack to store the value ofFOO
.The text was updated successfully, but these errors were encountered: