-
Notifications
You must be signed in to change notification settings - Fork 6
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
Rc variant and compressing pointer size #13
Comments
I would be interested in seeing this as a pr, even if just to add this to my own fork. Do you have a benchmark you can add to the repository to show the speedup? |
Thank you (both) for your PR/issues ❤️ |
So do you not use a static factory? If you do, what do you store in the map? Other than that, I think @Pat-Lafon's PR on having a derive-macro could help by having an attribute for that eventually. What do you think? |
Regarding the |
Here is a gist of what I'm currently using: https://gist.github.com/amarmaduke/d5abb2cc8f7f1b769f4af661bf701a32 I'm not using a static store. I pass around a container of all application state via mutable reference, the hashcons table is stored there. Another ask (that I'm willing to contribute): |
Thank you for the link, I will take a look.
Yeah I'm not surprised, that's the problem with |
@amarmaduke I'm a bit concerned with your hash function. It seems to me like like whenever a term is moved by memory management its hash will change. It will stay equal to itself, but if its placement in the factory relies on a previous value of the pointer then you won't find it since the hash has change, it might look in the wrong bucket. Does this make sense or am I speaking nonsense? |
This seems like a problem, but it hasn't been in practice for me. Here is my theory as to why that is: When we construct a new When we upgrade a The crate pin-weak gives an example of where generating a When the strong count falls to 0, then the I did some more small benchmarking on various encodings for
However, the Pin<Rc> case was pretty variable for some reason (from 12s to 16s), not sure why. The other benchmarks after a warm-up run did not have nearly as much deviation. To me it seems like there is a tradeoff here between two possibilities: 1. |
Thank you for this great answer. I'm not an expert in pinning, I'm going to research this a bit on my end to convince myself. |
Short term, how about this: we can have a branch on this repo that's the same but without the That way you can use this branch instead of your fork, and we can run experiments on a WIP version to make sure there's no problem. |
Alternatively, we could just feature-gate no-uid in the |
It's starting to sound like you're right: Since hashconsing will not let you mutate terms anyways, I think addresses must be stable like you said. Inner mutability would potentially break this, but it breaks hashconsing altogether anyways. That should probably be documented somewhere actually |
By the way @amarmaduke, it sounds like we will have quite a few configuration options soon, so I think @Pat-Lafon's PR #14 is the way to go. We would have a derive macro where you could (de)activate Would that work for you? |
Yeah, that would likely work for me, worst case it is future-proof to more knobs :) |
My thoughts exactly 😸 Let me take care of the proc-macro PR first then |
Hi,
I've been expermenting with hconsing with NBE for lambda calculus. This library is the primary inspiration, which I've mostly copied. Originally, I was using the library, but ran into some performance problems:
uid
is not needed, the internalNonNull
pointer data in theRc
is enough to act as a unique reference. As everyRc
is the spoke on a fuzzy ball surrounding aRcBox
, even if the location of theRcBox
were to somehow move, it must move in a way such that all constructedRc
's remain sound. Of course, theWeak
stored in theHConsign
has the same properties, because it references the sameRcBox
. Moreover, once the pointer is reclaimed, that is the exact condition in which the unique id would be reusable because the originalWeak
would fail to upgrade.Arc
with no ability to switch to anRc
. In my case, there is no point in being multithreaded. Parallelization in evaluating lambda terms is not very good unless you take an optimal lambda evaluator route."Fixing" those two problems were about a 2-3x speedup for my benchmarks, especially because lambda terms are explosive in terms of size, so halving the pointer size ends up being a useful win.
Ideally, I'd like these changes to make it into this library, because then I can just pull it from cargo :)
Unrelated, I would prefer if the pointer types where called
Hc
andAhc
, but this is a minor thing that is not important to me, I can just rename the types in my project.If you are interested I could draft a PR with the above changes.
The text was updated successfully, but these errors were encountered: