Re: [Sqlalchemy-tickets] [sqlalchemy] #2720: new C extensions for attribute accessing
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-05-08 03:07:13
|
#2720: new C extensions for attribute accessing
-----------------------------------+---------------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: enhancement | Status: new
Priority: medium | Milestone: 0.9.0
Component: cextensions | Severity: very major - up to 2 days
Resolution: | Keywords:
Progress State: not decided upon |
-----------------------------------+---------------------------------------
Comment (by claudiofreire):
Right. Well, {{{key in dict_}}} then {{{return dict_[key]}}} does the
lookup twice, and catching the !KeyError has to set up a try/catch block,
which is what is expensive about it (kinda like a stack bookmark CPython's
VM can roll back to).
But the real savings here come from:
* {{{Entity.id}}} goes from CPython's VM (LOAD_ATTR) directly towards the
C code, there's no frame setup or bytecodes involved (that's why the call
doesn't show up in profiles). With these ultra-cheap functions, frame
setup can be 90% of the cost.
* {{{PyBlah_Bleh}}} calls are all native. While, true, not immensely
quicker than equivalent VM bytecodes, the fact that they're just working
with simple dict ops and non-property attributes makes the VM itself a
hinderance. {{{Entity.id}}} was about a dozen opcodes, that's a dozen
loops over a huge switch block that interprets the bytecode. Now it's a
pair of native calls. That's '''way''' faster in comparison.
While those two wouldn't normally matter much in the overall picture, the
fact that properly optimized CPU-bound SQLAlchemy apps tend to be all
about reading attributes (in my experience), changes things.
I didn't try the timeit. I will as soon as I get back to my SA devel
machine (ie: the office).
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2720#comment:15>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|