Skip to content
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 using an RcVec type that collocates reference count with vector elements #336

Open
dtolnay opened this issue Jul 25, 2022 · 1 comment

Comments

@dtolnay
Copy link
Owner

dtolnay commented Jul 25, 2022

As of #335, TokenStream is Rc<Vec<TokenTree>>. This makes twice as many allocations as it should, because there's one that holds {strong count, weak count, data ptr, length, capacity} and a different one that holds the vector elements.

Let's look into putting these all into one allocation (except omit weak count, which we do not use) and see how it affects cargo bench --bench file --features full,parsing,test in syn.

@eddyb
Copy link

eddyb commented Jul 25, 2022

I believe such an RcVec would be roughly Rc<Thin<(len: usize, [MaybeUninit<T>])>> (or Rc<Thin<UnsizedVec<T>>> where UnsizedVec has both len and capacity as metadata).
A bit sad that we don't have the language tools to build something like that directly, but nonetheless, the functionality would be useful.

Also, I'm not 100% sure it's exactly the same, but I've been describing Lean4's Array T as being halfway between Rc<[T]> and Rc<Vec<T>>, with the intuition that it's RcVec<T>.
(For some context, Lean4 replaced GC with RC + auto-injecting Rc::make_mut, and not only does that make it faster than existing FP GC runtimes for functional data structures, it can ditch lists for flat arrays, as e.g. repeated RcVec::make_mut(xs).push(x) will only copy at most once).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants