the object relational mapper is not optimized for batching. this is mostly a product of the instrumentation SQLAlchemy applies to the attributes on objects, so that changes to attributes are tracked, and i see you are using the "threadlocal" mod below so it is also going to automatically add new objects to the Session, which then incurs more overhead because of cascading rules being fired off as well as each object is added. this is not to say it will always be impossible to do efficient batched inserts of large numbers of objects, but it would require the construction of some alternate methods of doing things internally that might require some flags or switches to be set for a particular session, for example. SA's focus within 0.1, 0.2 (plenty more version numbers to go....) has been on being as correct and bug free as possible. (im a believer in construct first, optimize second...SA is complicated enough without being constructed in a "pre-optimized" way). the "attributes" package is responsible for most of the instrumentation of attributes and ive been considering ways that it could be essentially redesigned to do what it does in a more lightweight fashion, although im not sure if the total length of codepaths would ultimately go down in such a case. also, the "session" idea plus all the hibernate-style cascading concepts are totally new to 0.2 and those features are still in their infancy; i havent put those through code profiling yet. there is a test script called "test/masscreate.py" in 0.1 and "test/perf/masscreate.py" in 0.2 which tests just the attribute package alone, which I spent a lot of time with profiling in order to speed up the attribute instrumentation. On my machine the 0.2 version is only 20% slower, so its possible the session stuff is adding the overhead. if you want to insert 1000 rows really fast, at the moment you might consider dropping into SQL expressions rather than ORM usage to do it, pending some more maturity of the 0.2 series. On Jun 7, 2006, at 10:38 PM, Robert Taylor wrote: Hi All, |
_______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users