-
-
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
simpler and faster message (de)serialize #21543
Conversation
base/distributed/messages.jl
Outdated
end | ||
end | ||
|
||
function deserialize_msg(s::AbstractSerializer) | ||
idx = read(s.io, UInt8) | ||
t = msgtypes[idx] | ||
return eval(current_module(), Expr(:body, Expr(:return, Expr(:call, deserialize_msg, QuoteNode(s), QuoteNode(t))))) | ||
if idx == 1 |
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.
A comment that idx
is the position of the type into the msgtypes
array would be useful.
base/distributed/messages.jl
Outdated
elseif idx == 9 | ||
return CallMsg{:call_fetch}(deserialize(s), deserialize(s), deserialize(s)) | ||
end | ||
assert(false) |
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 definitely looks uglier, hence a comment stating the reason why it is being done - probably the PR description itself - would be nice.
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 could generate this code automatically, but since there are only 9 cases I wasn't sure it would actually be easier to read. I can try it that way.
base/distributed/messages.jl
Outdated
@@ -183,7 +190,7 @@ function send_msg_(w::Worker, header, msg, now::Bool) | |||
try | |||
reset_state(w.w_serializer) | |||
serialize_hdr_raw(io, header) | |||
eval(current_module(), Expr(:body, Expr(:return, Expr(:call, serialize, QuoteNode(w.w_serializer), QuoteNode(msg))))) # io is wrapped in w_serializer | |||
serialize_msg(w.w_serializer, msg) # io is wrapped in w_serializer |
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.
?
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.
Can you be more specific?
base/distributed/messages.jl
Outdated
end | ||
end | ||
|
||
function deserialize_msg(s::AbstractSerializer) | ||
idx = read(s.io, UInt8) | ||
t = msgtypes[idx] | ||
return eval(current_module(), Expr(:body, Expr(:return, Expr(:call, deserialize_msg, QuoteNode(s), QuoteNode(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.
the outer "deserialize_msg" function will now need to be called with this "invokelatest"-style wrapper in order for (de)serialize to work (for custom added serialization functions after the event loop is initialized)
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 see, the issue is custom serialize
methods added after starting workers. We need a way to do this without allocating a bunch of objects and calling eval
.
Still working on this, and it will have to wait for #19784, but so far I have the pmap benchmark above down to allocating 41 MB. |
also separate `serialize_msg` from `serialize`
99fcff6
to
e62a7db
Compare
This fixes a couple things about message serialization.
serialize
whose output could only be consumed bydeserialize_msg
, so renamed toserialize_msg
.Some calls toNow useseval
were added here as part of the automatic recompilation of dependent functions #265 fix, but they don't seem necessary to me. I don't think anything adds new message types or methods to these functions, but correct me if I'm wrong.invokelatest
.serialize_msg
anddeserialize_msg
more specialized and efficient.Benchmark:
Before:
after: