This is a largely academic debate so apologies to other list readers for being off-topic.
On Sun, 26 May 2013 21:47:45 +0200 Juan Pedro Bolívar Puente <raskolnikov-mXXj517/z...@public.gmane.org> wrote: > > What makes you say that? I see you have experience in just about > > every interpreter expect Lua (btw I live next door in Valencia if you > > want to take it outside:). > > I am based in Berlin now, so lets argue here instead :) So... Ableton or NI? I was offered a job but couldn't con them into telecommuting :) > By "real-time constraints" I mean the real-time constraints that are > usually required in the engine of most audio applications, which require > algorithms to be O(bufferSize). Even non-GC heap allocations do not > qualify for this, and because closures and dynamic typing can not be > implemented without heap allocations (and GC) Lua has very fine-grained GC control otherwise it'd never run inside embedded devices or early-gen game consoles. To the extent modern C++ will have /some/ memory allocation (otherwise it's really ANSI C), good GC control may be even safer; it's easier to suspend/resume a VM if some time/CPU quota was reached than native code holding a mutex. Coders that design Lua-enabled engines take a simple perspective: what parts make sense in C/C++, what do in Lua. If some Lua logic become overwhelmed just move it to C++. In ~12 years of using Lua I came across a bottleneck only once (handling enormous flight-simulator samples); I moved that logic to a Lua C "userdata" in half an hour then it was solved. Now, a badly-written script driver can always do something stupid to abuse the VM but unlike web browsers, Mixxx isn't supposed to protect against hostile 3rd-party scripts. Although Wikipedia is switching to Lua and does provide such protections. > I don't think one can run Lua code in the engine threads. Do you mean secondary threads? Lua can definitely do that; I wrote a TUIO extension that ran Lua in its own thread and Lua context, while the main thread ran another Lua context. IIRC TUIO is OSC (or MIDI?) over UDP so you can't afford to lose packets either. Also, Lua has 'coroutines' or cooperative multitasking so you can run multi-thread logic in a single OS thread; Lua 5.2 can yield across C boundaries too. I know it's an old concept but everybody went all oh and ah about Go's 'goroutines' (seriously). > And if one can not run Lua code in the > engine threads, there is going to be an added latency anyway to send the > messages accross the engine boundaries, as long as the interpreter is > not really bad, I do not think this is a big issue. There's always /some/ latency to the extent you're running any CPU instructions. Typically, Lua-based engines use custom data types whose memory layout is defined in C, so there's no significant memory juggling when crossing C/Lua boundaries or moving data from one Lua context to another. > I would suggest you to take a look at "asm.js", a subset of > JavaScript used to compile new-generation C++ games to JavaScript that > run at 2X the native version (and it is the whole game running in JS, > even the engine!). I know asm.js but frankly using a LLVM backend is no different than JIT. Any scripting language that can allocate & fill executable byte arrays could do the same, f.ex. the book "Lua programming gems" has a chapter using Fabrice Bellard's Tiny C Compiler (from boot-linux-from source code and Qemu fame) to embed native C code in Lua code. IMHO it's a pointless pursuit though; VMs should be sandboxed and prevented from generating new machine language at runtime. > > Lua's used by Reason and ReNoise and in game engines since the PS2 > > all the way to Crytek's Far Cry/Crysis which have similar > > frame-lock/tick constraints. There's a laundry list of realtime apps > > on www.lua.org/uses.html. Most tellingly, you'll find it in many > > embedded systems like Cisco, Barracuda, MicroTik RouterOS, OpenWrt, > > Wavecom GSM firmware. It hardly gets more realtime than that. > > Ok, that means its fast, but not real-time in the sense I mean, because > they do not have a deadline. I know, you mean "critical real-time". > Or to put otherwise: in Far Cry if a > single frame takes 50ms instead of an average of 16 (assuming 60fps) it > will most probably go unnoticed. Nope it's exactly the same problem; both audio and video have the concept of frames. Missing a video monitor's vertical blank refresh (VBL) to draw a frame is like missing an audio frame; in one case you have tearing because it'll show an old frame, potentially very old since 3D cards are heavily pipelined with several pre-buffered frame, in the other you have a dropout or if the audio card's buffers are looping it'll click. In a professional application, video tearing is an unacceptable as audio dropouts. Video games have very large audiences and budgets, larger than Hollywood movies. Locking to a video frequency/bit-depth is as critical as it is for audio. > > I wrote something like that and used it on all but my very first > > gigs. I attached the glue code and script here; initialization is at > > the bottom. Please don't judge Lua's merits (or mine for that > > matter:) based on this, it was never meant to be used/seen by anyone > > but myself, is/was a work in progress and I frequently tweaked > > scripts just before a gig, knowing full well it was pretty > > risky/stupid. > > Nice effort! Maybe you could put that in a branch in bzr so its easier > for people interested in Lua can grab it and maintain it or reuse parts > of it. Nah, it was a hack on top of missing Traktor functionality, I have no use for it anymore. OTOH I'd like to integrate my other audio project, CDJ2MIDI, into xwax or mixxx, not sure yet where. Take a look at its source code in case you still think I don't get "critical realtime" :P > > I'm fairly sure Lua is one of the most concise languages there is. > > Its reference manual is 103 pages long, including the C API. Also Lua > > 5.2 has a rich set of binary operators (for example bit range > > extract, ROL/ROR) that'd help HID/MIDI processing. > > By concise I meant with regards of the code written in the language. You mean to minimize Mixxx's ./res/controller/ scripts? I read the HID documentation and Lua 5.2's bit manipulation library would definitely help, more significant is Lua's native C types extensibility. Typically 3D engines will wrap low-level C++ classes into a single, higher-level Lua objects. Wrt to the language itself, there are ways to drastically grind down algorithms' verbosity but it's inversely-proportional to code readability, something like the obfuscated C contest. > Anyway, I understand the merits of Lua w.r.t performance and so on. > However, I do not see these strong enough to compensate for the benefits > of JavaScript (many people know it, other languages can be compiled to > it, wide choice fo VMs, etc.) Fair point. To my defense I replied to an existing thread title "Hate Javascript" that was introducing a new language (or variation thereof), with others saying that part of Mixxx was problematic. I'm in no position to say whether a switch is warranted / if the disruption is worth it long-time and even if it were, what priority it'd have. IMHO the scripting language is less important than the inability to QA hardware interfaces you don't physically have in front of you, maybe there's some way to unit-test them by recording a baseline audio track with raw MIDI/HID samples on another audio software and use the output to compare how the driver behaves in Mixxx, just thinking out loud. That being said, I do have experience in both Javascript and Lua and know the LuaVM inside out, my paying/daytime job is writing a Lua debugger. One of the many things that sets Lua apart is that it isn't a runaway, feature creep language; its creators have a laser-sharp focus and insist on mind-boggling elegant design. Most applications I wrote ended up embedding Lua's VM because it's such a no-brainer to integrate. cheers, -- p > ------------------------------------------------------------------------------ > Try New Relic Now & We'll Send You this Cool Shirt > New Relic is the only SaaS-based application performance monitoring service > that delivers powerful full stack analytics. Optimize and monitor your > browser, app, & servers with just a few lines of code. Try New Relic > and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may > _______________________________________________ > Get Mixxx, the #1 Free MP3 DJ Mixing software Today > http://mixxx.org > > > Mixxx-devel mailing list > mixxx-devel-5nwgofrqmnerv+lv9mx5uipxlwaov...@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/mixxx-devel > ------------------------------------------------------------------------------ Try New Relic Now & We'll Send You this Cool Shirt New Relic is the only SaaS-based application performance monitoring service that delivers powerful full stack analytics. Optimize and monitor your browser, app, & servers with just a few lines of code. Try New Relic and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may _______________________________________________ Get Mixxx, the #1 Free MP3 DJ Mixing software Today http://mixxx.org Mixxx-devel mailing list Mixxx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mixxx-devel