Latency of copying a dict between a node process and max?


    Feb 18 2019 | 2:59 am
    Hi, I'm wondering if anyone can tell me what kind of latency we get when using the node script api to copy a dict to or from max. And maybe what actually goes on under the hood to make this possible? Is there some shared memory kung fu in there or does it just wrap streaming the dict over a socket?
    thanks! iain

    • Feb 18 2019 | 7:08 pm
      Hi Iain,
      sure. Let me try to answer your questions here.
      While I do like the phrase, there is no shared memory kung fu going on. On a higher level the [node.script] object is taking care of the process management, setting up all the communication connections etc. When using the "max-api" module we leverage a Unix Domain Socket (OSX) / Named Pipe (Windows) based IPC to communicate directly between the Node and Max process. There is far more to it to support the whole feature set of [node.script] but maybe this answers your questions.
      Thanks, Florian
    • Feb 18 2019 | 9:12 pm
      Thanks Florian. Is there any online docs or further resources where I could read more about what goes on under the hood?
    • Feb 18 2019 | 10:46 pm
      Hi Iain,
      If you want to check out the nitty gritty (without tons of support from us on our end), you can look inside the Application bundle (on OS X) or resources folder on Windows at the Node for Max node.js source and figure out the client end there. For example, check out the _parseAndEmitMessage() function inside /Applications/Max.app/Contents/Resources/C74/packages/Node\ For\ Max/source/lib/communication/socket.js
      There you will see that it reads a serialized JSON object which is parsed and sent to your script's code. Pretty standard web communication techniques, even if slightly different than using web sockets (for more information on such a technique you could google "send JSON over sockets")
      As to latency it will depend on lots of variables. I'd recommend you use something like the Date object in JS to send a time to your node.script object and use another Date object on that end to see what the time delta is. They both should be referencing the same underlying system time, and you will get much more precise numbers than anything I could wave my hands at from afar.
      Hope this helps, Joshua
    • Feb 19 2019 | 1:30 am
      This is super helpful, thanks for taking the time. I will post a more detailed reply later but wanted to say thanks first. :-)