Mats Kindahl <[email protected]> writes: > Jim Starkey wrote: >> JavaScript and Lua share many of the same problems. Consider the >> following: >> >> function outer (x) >> { return function { alert x }} >> var inner = outer(42); >> inner(); >> >> The last statement, of course, displays "42". The baggage to capture >> closures and bind them to functions induces significant overhead in >> execution cost, a cost I don't think is justified. > > An upvalue is only generated if necessary in Lua and I assume that is the case > for JavaScript as well. > > Although it is hard to judge how the implementation is affected by the need to > support lexical scoping, benchmarks show that the speed of Lua (lexical > scoping), Perl (lexical scoping), Python (not lexical scoping) is comparable, > while they all beat PHP (no lexical scoping). All of these are of course > slower > than Java (no lexical scoping), but OTOH, Scala (lexical scoping) has > comparable > performance to Java. > > So, in short, there is no evidence available to me that closure induces > significant overhead in execution cost by just by being part of the language.
Having closures requires having automatic garbage collection (*). And automatic garbage collection carries a cost (not just performance, but also in constraints regarding the interfacing with other memory models in the system). But once garbage collection is in, I believe there is no further significant cost to closures (at least not for code that does not use them). So I would think that the significant question is whether one is willing to pay the price of having a garbage collected language embedded in the database server, something that has both some cost, and also significant benefits in terms of expressiveness also apart from closure support. Also, there is currently significant efforts going on in terms of efficiently running Javascript code, so I would expect that Javascript will be one of the most attractive scripting languages in terms of raw performance (though I'm not sure how important that is for a database server). - Kristian. [(*) Technically, one could imagine having closures without garbage collection, however in practise people expect to be able to build and pass around closures without having to manually free them at the right spot.] _______________________________________________ Mailing list: https://launchpad.net/~drizzle-discuss Post to : [email protected] Unsubscribe : https://launchpad.net/~drizzle-discuss More help : https://help.launchpad.net/ListHelp

