-
Notifications
You must be signed in to change notification settings - Fork 1
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
Alternative implementation based on an OwnedEnv. #1
Conversation
Wow, this is incredible! 😃 I will try it out it in the Idris 2 compiler later today. Thank you so much! ❤️ |
The outer ResourceArc is enough so we do not need the extra Arc. Naming of the new resource datastructure has been altered for clarity. It's now a 'MutableTermBox'.
Thanks for this change! ❤️ I noticed that the pull request went into the I have done a little bit of testing on this branch, and it might appear that there is a performance bottleneck. I have not done any profiling yet. I will look into it tomorrow. To make testing easier I have added an option to In the erlang branch of this repo I have modified the NIF to work with an Erlang module called How to run mutable_storage from code generated by Idris 2If you want to try it out, you can follow these steps: Create an Idris module called import Data.IORef
main : IO ()
main = do
x <- newIORef 42
let y = x
writeIORef y 94
val <- readIORef x
printLn val
val <- readIORef y
printLn val
modifyIORef x (* 2)
val <- readIORef x
printLn val
val <- readIORef y
printLn val Build From the
Run the program using: The setup is a bit inconvenient, but it should be possible to package this up in a better way later. |
I have now done some benchmarking. See bench.exs in the ioref-benchmark branch. To run the benchmark:
Here are the results that I got:
Overall, the NIF is quite a bit slower than using the process dictionary 😕 Even if the performance is not the greatest, this NIF can still serve a purpose: Avoid leaking memory. |
I have no clue as to the performance of this implementation, but it at least is able to store Erlang references correctly and it does not leak memory.
c.f. chrrasmussen/Idris2-Erlang#4