From 3347b798917122137f9957eb0d27accb004f696c Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Vargas Date: Wed, 21 Sep 2022 20:01:35 -0500 Subject: [PATCH] Flatten message types This Reduces allocations a tiny bit. --- src/Malt.jl | 10 +++++++--- src/worker.jl | 9 +++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Malt.jl b/src/Malt.jl index 45242fe..5eccd74 100644 --- a/src/Malt.jl +++ b/src/Malt.jl @@ -61,18 +61,22 @@ end _new_call_msg(send_result::Bool, f::Function, args...; kwargs...) = ( header = :call, - body = (f=f, args=args, kwargs=kwargs), + f=f, + args=args, + kwargs=kwargs, send_result = send_result, ) _new_do_msg(f::Function, args...; kwargs...) = ( header = :remote_do, - body = (f=f, args=args, kwargs=kwargs), + f=f, + args=args, + kwargs=kwargs, ) _new_channel_msg(expr) = ( header = :channel, - body = expr, + expr = expr, ) function _send_msg(port::UInt16, msg) diff --git a/src/worker.jl b/src/worker.jl index 53ff61d..e08fe14 100644 --- a/src/worker.jl +++ b/src/worker.jl @@ -51,9 +51,8 @@ end function handle(::Val{:call}, socket, msg) - body = msg.body # Don't use destructuring to support v1.6 try - result = body.f(body.args...; body.kwargs...) + result = msg.f(msg.args...; msg.kwargs...) # @debug("Result", result) serialize(socket, (status=:ok, result=(msg.send_result ? result : nothing))) catch e @@ -65,17 +64,15 @@ function handle(::Val{:call}, socket, msg) end function handle(::Val{:remote_do}, socket, msg) - body = msg.body try - # @debug("Remote do:", body) - body.f(body.args...; body.kwargs...) + msg.f(msg.args...; msg.kwargs...) finally close(socket) end end function handle(::Val{:channel}, socket, msg) - channel = eval(msg.body) + channel = eval(msg.expr) while isopen(channel) && isopen(socket) serialize(socket, take!(channel)) end