You are reading content from Scuttlebutt
@Soapy mcSoap %YfXU8AHfPjWnX2h4njHXMKiF3Ed/KRcQ0MI/UesSo6o=.sha256
Re: %+CGAZUQ0m

moonhermit is quite nimble. It is statically linked to Libsodium and Lua and weights only 664k on my Mac. It might not be as fast as NodeJS based stuff, but it is smol and it is fast enough.

The main challenge I see at the moment is that muxrpc calls which generate streams are collected before the data is sent back into the Lua script. This is slower than just pull-streaming. You can still create pull-stream like code, but the stream will be fully computed before being sent through the pipeline.

An example of streams:

-- counts contact messages.

function justContacts(m)
    return lookup(m, "value", "content", "type") == "contact"
end

function displayContactMsg(m)
    local user = m.value.author
    local target = m.value.content.contact 
    local action = m.value.content.following and "followed" or "unfollowed"
    print(string.format("%s %s %s", user, action, target))
end

local msgs, err = ssb:createHistoryStream({
    id = arg[1],
    limit = 50000
})

if (not err) then
    stream(msgs).filter(justContacts).foreach(displayContactMsg)

    local contactMsgs = stream(msgs).filter(justContacts).toarray()
    print(string.format("%d contact msgs", #contactMsgs ))
else
    print(err)
end

That example is a bit naive as it runs through the stream twice: once to print the messages, and then again to count them. It is straightforward code, good enough for throwaway scripts.

This script runs in about 1 second on my machine:

172 contact msgs
./moonhermit test4.lua "@qv10rF4IsmxRZb7g5ekJ33EakYBpdrmV/vtP1ij5BS4=.ed25519  0.77s user 0.06s system 72% cpu 1.140 total

not bad for something that is looping all messages in my feed twice.

Join Scuttlebutt now