[Bf-python] Strange behavior of Pysqlite

Martin Poirier theeth at yahoo.com
Mon Dec 5 15:25:54 CET 2005



--- Roland Hess <rolandh at reed-witting.com> wrote:

> Not really looking for a solution to this, as the
> workaround is 
> simple enough, but I did want to point this out for
> posterity's sake.
> 
> I'm using SQLite in Blender via the Pysqlite Python
> package. When I 
> make my connection object and cursors as standard Py
> objects, they 
> work fine. But, when I set those objects as objects
> of the global 
> Blender object for use across different functions
> (Blender.dbConn and 
> Blender.dbCursor) as opposed to simply passing them
> as non-global 
> objects (dbConn and dbCursor) as parameters of the
> functions, I 
> experience a significant slowdown. I didn't have
> this problem when 
> using Blender with MySQL and the MySQLdb Python
> package. I have 
> absolutely no idea where one would look to solve
> something like this, 
> and my guess is that it's a complete non-issue, as
> the amount of 
> people doing what I'm doing is probably very near
> zero. Anyway, a 
> quick example to show:
> 
> from pysqlite3 import dbapi2 as sqlite
> dbConn=sqlite.connect("dbActors.db")
> dbCursor=dbConn.cursor()
> 
> Blender.dbConn = dbConn
> Blender.dbCursor = dbCursor
> 
> dotest(dbConn,dbCursor)
> 
> def dotest(dbConn,dbCursor):
>     SQL="INSERT (x) INTO tblActors VALUES (5);"
>     for i in [0..2200]:
>        dbCursor.execute(SQL)
>     dbConn.commit()
> 
>     for i in [0..2200]:
>        Blender.dbCursor.execute(SQL)
>     Blender.dbConn.commit()
> 
> Assuming correct syntax on the Python code and the
> SQL (didn't bother 
> to look it up for this email), I get results of
> around 1.13 seconds 
> for the test using the passed objects (dbConn), and
> around 86 seconds 
> for the test using the global object
> (Blender.dbConn).
> 
> Strange. That's all I'm saying.

IIRC, the python bytecode compiler optimizes look up
of function parameters, so in theory, there would be a
slight speed up using the parameters, however, nothing
quite on the scale of what you're getting. (passing
through Blender is a double dictionnary lookup, once
for the Blender module and a second time for the
properties)

Can you try putting them in a dummy class to see if
it's the blender module lookup that's slow? Something
like:

class foo:
    pass

foo.dbConn = dbConn
foo.dbCursor = dbCursor


Very strange indeed.

Martin


		
__________________________________________ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 




More information about the Bf-python mailing list