LUA is the toy language for those who enjoy the Forced Flushing Of L1/L2 Cache per operation. In fact, every operation causes several L2 cache misses during table look-ups, flushing both the L1 and L2 caches.
>>119 overuse of object oriented (OOP) constructs >>117-118 doesn't use OOP. incorrect usage of design patterns >>117-118 doesn't use any design pattern. overuse of OOP methods/functions/procedures >>117-118 uses only the strict necessary. declarative programming >>117-118 does the same as >>114, if one it's considered bloated for this, the other will be too. excessive loop unrolling >>117-118 doesn't even use loops. excessive use of multiple conditional If statements
See: declarative programming. It also uses just one if. dead code
All the code is reachable. redundant calculations
`it' is evaluated once.
So, you started whining about something you don't even know? Perfect.
(defmacro aif (p t f)
`(let ((it ,p))
(if it ,t ,f)))
; later...
(defun if (x) x)
(aif (if 2) it 3) ; expands to: (let ((it (if 2))) (if it it 3))
; but now if it's being shadowed by if!!!
; it doesn't work
(define-macro (aif p t f)
#:capture it
#'(let ((it p))
(if it t f)))
; later...
(define (if x) x)
(aif (if 2) it 3)
; this expands to (let ((it (if 2))) (the-old-if it it 3))
; OMG IT WERKZ!!
; `if' it's just looked up in the scope of the macro definition!!
Name:
Anonymous2011-02-07 19:37
>>134
>(defun if (x) x)
But my `if` resides in package cl-user, and `aif` uses `if` from CL! I guess crappy academic Scheme just doesnt have packages, like CL and Clojure do.
Name:
ve seen it before!!112011-02-07 19:40
hygienic
Sometimes, you’re on a team, and you’re busy banging out the code, and somebody comes up to your desk, coffee mug in hand, and starts rattling on about how if you use multi-threaded COM apartments, your app will be 34% sparklier, and it’s not even that hard, because he’s written a bunch of templates, and all you have to do is multiply-inherit from 17 of his templates, each taking an average of 4 arguments, and you barely even have to write the body of the function. It’s just a gigantic list of multiple-inheritance from different classes and hey, presto, multi-apartment threaded COM. And your eyes are swimming, and you have no friggin’ idea what this frigtard is talking about, but he just won’t go away, and even if he does go away, he’s just going back into his office to write more of his clever classes constructed entirely from multiple inheritance from templates, without a single implementation body at all, and it’s going to crash like crazy and you’re going to get paged at night to come in and try to figure it out because he’ll be at some goddamn “Design Patterns” meetup.
>>136
If he's writing code that he expects you to use but that code doesn't match the design spec, just tell him you're not going to bother with it until the spec is updated.
>>135 I guess crappy academic Scheme just doesnt have packages
It has But my `if` resides in package cl-user, and `aif` uses `if` from CL!
Enjoy your name clashes and gensyms, ``faggot''.
LuaJIT and Lua/LLVM still using those god damn look-up tables in the JITed code.
The table look up certainly isn't ideal, compared to indexing into an organized location within a struct, but it isn't that bad. Strings in lua are interned into a symbol table, which means that all strings with equal contents are actually the same string, starting at the same memory address. Because of this, using strings as keys in a hash table in lua is as efficient as using pointers as keys. Also, many class-like and struct-like tables in lua don't usually have that many fields, maybe 12 or 15 at the max, unless of course there is a massive amount of inheritance going on. Any more and it wouldn't be easy for a programmer to follow the code. A typical hash table using some type of probing scheme will usually keeps it's array length around twice as much as there are objects in it, yielding structs that are around twice as large as they normally would be. This a cost, but it isn't that bad. Lua is a simple language, and typically out performs other interpreted languages. It's flaws aren't in speed. You can certainly criticize it for not having any support for threads, and having a pretty limited standard library. You can't even do a chdir without extending it with C, and there isn't built in support for real regular expressions, which is a little baffling for me since it is a scripting language and regex is usually their niche.
yeah me too. I'm sure developers using it in games would really appreciate it. It wouldn't require very much deviation from the language either, in fact, it might be implementable as is with some crazy hacks. Because nothing can actually be stored within a struct, just references to other values, a struct with n fields of arbitrary types can be implemented as a lua table using only the indecies, 1 .. n as keys. Doing this would ensure that it would look like a regular array under the hood. Then you could have table mapping field names to positions within the array:
apple_struct_field_locations = {num_seeds = 1,
color = 2,
age = 3}
and then, somehow have lua locate every point in your code where an apple_struct is being indexed by one of the three constant keys above, and inline replace it:
And since it's closedsource, there's a very good chance it's just vanilla Lua with some minor internal changes, like name, file extensions, maybe even changes in the bytecode generator.
But hardly anything that could possibly classify as ``better''.
Name:
Anonymous2011-09-24 19:21
why don't they just get an L3 cache on the XBox? :/
Name:
Anonymous2011-09-24 19:22
I'm guessing poor Lua performance comes from guys who don't understand how lexical closures work and so make hash tables for every persistent bit of data.
Poor perforamnce is caused by cretins who write inelegant bullshit, not languages.
>>150
Lexical closures still require more space per slot than a properly-packed zomg-optimized structure. Just saying, I'm an avid defender of closures but I don't find that they are a proper replacement for structs.
Name:
Anonymous2011-09-24 22:14
>>154
but they don't cause a cache miss every line like self.foo does.
function make_value(v)
return function() return v end,
function(new_v) v = new_v end
end
function make_struct(...)
local functions = {}
for i,v in ipairs({...}) do
getter, setter = make_value(v)
table.insert(functions, getter)
table.insert(functions, setter)
end
return unpack(functions)
end
function main()
local get_name, set_name,
get_age, set_age,
get_gender, set_gender = make_struct('John', 34, 'male')
print(get_name()) --> prints John
print(get_age()) --> prints 34
set_age(56)
print(get_age()) --> prints 56
end