-
Notifications
You must be signed in to change notification settings - Fork 58
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
support adding atoms 'zero-copy' #361
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 7507336535
💛 - Coveralls |
fa5f68f
to
ee53860
Compare
3cb70df
to
e0c328c
Compare
Have you considered creating a wrapping object (That said, I've had lots of great ideas with lifetimes and python that end up not being feasible, so it's possible there are shortcomings here. Also wresting with lifetime error messages is sometimes just not worth it.) |
you mean having the allocator contain One thing that would make me a little bit uneasy is that we can take both |
…s to the Allocator
e0c328c
to
99e6b22
Compare
in its current form, this patch causes a performance regression. When testing on RPi5:
|
I think the main use case for this is block references being passed in to the generator. I will update this at some point with that use case in mind. |
'This PR has been flagged as stale due to no activity for over 60 |
This adds a feature to the
Allocator
and itsNodePtr
where aNodePtr
can point into a pre-existing, immutable, buffer. Currently, aNodePtr
atom can only point into the (dynamically allocated) heap. TheNodePtr
representation has 6 bits to encode "type", which currently is eitherBytes
orPair
. This adds 3 additional types, indicating which external buffer the atom is allocated in.The main rationale are to reduce memory footprint and avoid unnecessary memory copying when:
This patch doesn't in itself take us all the way there, but it adds the basic support for it in
Allocator
.Lifetime annotation
With this change,
Allocator
needs a lifetime annotation, to ensure the buffers added to it (viaadd_external_buffer()
) do in fact outlive the allocator itself.This lifetime annotation propagates to
LazyNode
, which contains a reference to anAllocator
. The problem is that pyo3 cannot expose types with lifetime annotation to python.This is solved by "laundering" the
Allocator
when creating aLazyNode
, by turning it into anImmutableAllocator
, which simply does not contain any references to the external buffers, and will just fail if any such nodes are part of theLazyNode
tree. (None of the intended use cases for external buffers returnLazyNode
s, so this shouldn't be a problem).ObjectType
The main reason to hard code the indices in
ExternalBytes0
,ExternalBytes1
is to keep the enum a plainint
, to support casting it in the shift-expression when constructing the underlying value of aNodePtr
. I suspect that we can make this a little bit nicer by detaching the enum's representation from theNodePtr
representation.as_index()
As we add more object types to
NodePtr
, the purpose ofas_index()
is probably increasingly defeated. It was introduced as a cheap and efficient alternative to a hash-table withNodePtr
as the key.