Gen vs javascript (vs Max ?)

Mattebass's icon

Hello,
someone has some informations about the efficiency of gen (event domain gen, without ~) respect to js or native max objects? In particular,
does gen has the same problem of low priority in the scheduler as like as js?
Thanks in advance

Iain Duncan's icon

Hi Mattebass, I don't know but I'm interested in hearing. You might be interested in trying out Scheme for Max, which allows you to do your code in S7 scheme-lisp and runs in the high priority thread (if triggered in the high priority thread), ie same threading as normal max and no auto-defer low like in JS I plan to add functions to control the threading better in upcoming releases too. Info here: https://iainctduncan.github.io/scheme-for-max-docs/overview.html

Roman Thilenius's icon


someone here on the forums once said that javascript would be about 50 times slower than processing messages in max.

Iain Duncan's icon

These sorts of things really depend on what you are doing, but in my benchmarks of some really simple operations (counting up to 1million and multiplying each count by a float), I only see about a 3 times speed decrease from plain max to JS. This is with both running in the UI thread. Basically the same operation is 450ms in scheme, 500 in js, 175 in max (uzi, counter, *). I haven't tested Gen though

Iain Duncan's icon

FWIW I figured out how to test them running from the high priority thread, and this lowers the JS performance a bit, presumably from the deferred low call under the hood. But roughly the same.

Mattebass's icon

Thanks for the answers. In particular I was tying to figure out the usefulness of gen compared to javascript, and maybe the reason is based on gen's better performance. Moreover, I was trying to figure out what computational advantages could provide gen, because if gen~ works on a per-sample way, it's not clear how the as-fast-as-possible paradigm of regular max object could be improved by gen.
Anyone has some empirical knowledge about this?
Thanks again

Iain Duncan's icon

I have not used Gen much, but in a nutshell, Gen code compiles down to C++ under the hood, so when you run it, it's running much like an external. So it should run much faster than JS (or scheme) as there is no interpreter overhead, especially for certain kinds of operations.

Jolon Dixon's icon

I’m curious for a more in-depth answer from someone at cycling ‘74 - when to use gen or gen~ or stick with javascript (or indeed use lua?).

Jean-Francois Charles's icon

That really depends on your end goal. For many situations, good old Max is extremely good.
gen~ is most useful when you want to process sounds sample per sample.
Javascript is appreciated in some situations but it is always executed in a low priority thread, so, if you are working with MIDI data, timed events, sequencers, etc, it is generally not that useful.
If you share your precise application, you might get more useful answers.

Jean-Francois Charles's icon

And of course if you're talking Jitter, it depends if you want the processing to happen on the CPU (gen may be useful in complement to Jitter objects) or GPU (shaders, etc.)

Iain Duncan's icon

I should weigh in that if you are looking for what JS does but in the high priority thread, Scheme for Max does this.