-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: serialize pointer- and padding-free objects in one write #14678
base: master
Are you sure you want to change the base?
Conversation
@@ -674,6 +678,11 @@ function deserialize(s::SerializationState, t::DataType) | |||
end | |||
if nf == 0 | |||
return ccall(:jl_new_struct, Any, (Any,Any...), t) | |||
elseif t.pointerfree && ccall(:jl_datatype_haspadding, Cint, (Any,), t)==0 | |||
x = ccall(:jl_new_struct_uninit, Any, (Any,), t) | |||
a_ = pointer_to_array(convert(Ptr{UInt8},pointer_from_objref(x)), sizeof(t)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is regrettable but there are no read!
methods that accept a pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've thought they should be unsafe_read!
and implemented consistently instead of the current ad-hoc implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
Oh bloody hell this ends up routing around the code that serializes |
Le sigh. Should probably just add the |
But then, why is |
What about |
Those types currently can't be serialized at all. And for the sake of not making people's parallel code slow as hell, let's hope they never can be. |
else | ||
writetag(s.io, UNDEFREF_TAG) | ||
if t.pointerfree && ccall(:jl_datatype_haspadding, Cint, (Any,), t)==0 | ||
write(s.io, pointer_from_objref(x), sizeof(x)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the pointer returned here may be to a box that is not gc-rooted. in general, pointer_from_objref
should never be called on something that is immutable
and pointerfree
(I think we should make it an error)
i'm looking into possible alternatives that would provide the same benefit, but doesn't require calling pointer_from_objref
This is a hack to try to address #14106. Any objects that contain no references and no padding can be sent as a single binary blob, instead of iterating over the fields which entails expensive boxing.
Before:
after: