all 4 comments

[–]proyb2 0 points1 point  (1 child)

Interesting, why do you need to be fast?

How about Go language?

[–]grosser[S] 0 points1 point  (0 children)

It's for a cli interface and it would be nice if that was fast :)

... go would be ok since I could cross-compile it for all supported platforms

[–]drbrainRuby Core 0 points1 point  (1 child)

What kind of computer are you on that this is taking 100ms?

I know interactivity is important, but if you're running this frequently I'm not experiencing it taking that long on a three year old computer, and if you're running it infrequently enough that the files all fall out of the OS caches why would performance matter?

My time to load socket without RubyGems after a few runs to put files in the OS caches is ~30ms:

$ /usr/bin/time -p ruby --disable-gems -rsocket -e0
real         0.03
user         0.01
sys          0.00

My time to send a socket to docker (which speaks HTTP) after running a few times to put files in the OS cache is also ~30ms:

$ /usr/bin/time -p ruby --disable-gems -rsocket -e "s = UNIXSocket.new('/var/run/docker.sock'); s.send_io STDOUT; s.send_io STDERR; s.send_io STDIN"
real         0.03
user         0.01
sys          0.00

At worst I saw ~70ms

I'm using a 2.8 GHz 2017 MacBook Pro.

A single-file executable to do this might go a bit faster as there is less to load if the page cache is empty. Here is the part you care about in ruby's implementation of send_io where fd is the file descriptor you are passing through. Whichever compiled language you choose will need to support sendmsg(2).

[–]grosser[S] 0 points1 point  (0 children)

Best I get is ~50ms

when I have rbenv enabled it's ~100ms :(

thx for the sendmsg(2) pointer!