merits of Lisp vs Python

Alex Mizrahi udodenko at users.sourceforge.net
Sat Dec 9 06:14:02 EST 2006


(message (Hello 'Andrea)
(you :wrote  :on '(Sat, 09 Dec 2006 11:08:34 +0100))
(

??>> so we can see PyDict access. moreover, it's inlined, since it's very
??>> performance-critical function.
??>> but even inlined PyDict access is not fast at all. ma_lookup is a long
??>> and hairy function containing the loop.

AG> I once had a crazy idea about the lookup speed problem;
AG> can't the lookup result be cached in the bytecode ?

actually i don't see any reason why lookup is needed at all.
i think you can use approach similar to Lisp Symbols in Python, so it's
implementation slow, not the language.
there are some subtle differences -- for example, if you del global binding,
function gets undefined, but in Lisp uninterning does not invalidate code
that uses that symbols. but you can easily override this invalidating the
symbol bindings.

i think symbols can be implemented just as cache you suggest, but without
need of timestamp, but with additional indirection.
you should associate a SYMBOL with each entry in the globals dict, however
those SYMBOL lifetime should be managed independently (lifetime management
is one of difficulties, but i think not non-solvable). once you need to
cache lookup, you cache a SYMBOL pointer.
then you just get symbol's value on firther lookups. if dict gets update, it
should update all symbols associated with it. if entry (or whole dict) is
deleted, it should invalidate all symbols, so accessing them will produce
error, but it should not delete symbols.
you can resolve symbols not on first access, but during the read operation
(when bytecode is produced), as it's done in Lisp.

however, it's only applicable to LOAD_GLOBAL and STORE_GLOBAL, i think it
won't be possible to optimize STORE_ATTR that way without changing
semantics.

by the way, maybe some optimizations are already implemented in Psyco?
it's Python JIT with profile-guided type optimization, but i don't know how 
it deals with lookups..

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity")





More information about the Python-list mailing list