]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- another easy win, cache the calc of bind processors in the compiled object
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Dec 2010 22:50:25 +0000 (17:50 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Dec 2010 22:50:25 +0000 (17:50 -0500)
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/util/_collections.py
test/aaa_profiling/test_resultset.py
test/aaa_profiling/test_zoomark.py
test/aaa_profiling/test_zoomark_orm.py

index 21603b2586a3f49e46b6a1abc990cd626466b000..22fff3312019417499a400abc244f514c3f56be9 100644 (file)
@@ -402,13 +402,8 @@ class DefaultExecutionContext(base.ExecutionContext):
             self.__process_defaults()
             self.postfetch_cols = self.compiled.postfetch
             self.prefetch_cols = self.compiled.prefetch
-                    
-        processors = dict(
-            (key, value) for key, value in
-            ( (compiled.bind_names[bindparam],
-               bindparam.bind_processor(dialect))
-              for bindparam in compiled.bind_names )
-            if value is not None)
+        
+        processors = compiled._get_bind_processors(dialect)
 
         # Convert the dictionary of bind parameter values 
         # into a dict or list to be sent to the DBAPI's 
index eb339cf1d454e23c7a40671bc7a66f618e93d104..d5b877a3582f1d5471b115261c5d4c80e3a927bb 100644 (file)
@@ -250,7 +250,26 @@ class SQLCompiler(engine.Compiled):
         # a map which tracks "truncated" names based on dialect.label_length
         # or dialect.max_identifier_length
         self.truncated_names = {}
+        
+        # other memoized things
+        self._memos ={}
 
+    def _get_bind_processors(self, dialect):
+        key = 'bind_processors', dialect.__class__, \
+                    dialect.server_version_info
+        
+        if key not in self._memos:
+            self._memos[key] = processors = dict(
+                (key, value) for key, value in
+                ( (self.bind_names[bindparam],
+                   bindparam.bind_processor(dialect))
+                  for bindparam in self.bind_names )
+                 if value is not None
+            )
+            return processors
+        else:
+            return self._memos[key]
+        
     def is_subquery(self):
         return len(self.stack) > 1
 
index 6739c6d0966090a9bd0a929160879e1894316004..ef315445d0902ff850c56b0d7c337b8a74017caa 100644 (file)
@@ -54,9 +54,9 @@ class frozendict(ImmutableContainer, dict):
         if not self:
             return frozendict(d)
         else:
-            d2 = self.copy()
-            d2.update(d)
-            return frozendict(d2)
+            d2 = frozendict(self)
+            dict.update(d2, d)
+            return d2
             
     def __repr__(self):
         return "frozendict(%s)" % dict.__repr__(self)
index da8653184d9dea096b48d6bbedc64320dbe76bb6..f56bfc73e307e8ba649a93b07d70972da6e2520a 100644 (file)
@@ -30,7 +30,7 @@ class ResultSetTest(TestBase, AssertsExecutionResults):
         metadata.drop_all()
 
     @profiling.function_call_count(14416, versions={'2.4': 13214,
-                                   '2.6+cextension': 409, '2.7+cextension':438})
+                                   '2.6+cextension': 390, '2.7+cextension':401})
     def test_string(self):
         [tuple(row) for row in t.select().execute().fetchall()]
 
index 85e41618403322909125cf38bb313e0bda0de334..4bd4c9d09aa4ee42c79184e69339b2b6a2cfedc2 100644 (file)
@@ -389,7 +389,7 @@ class ZooMarkTest(TestBase):
     def test_profile_6_editing(self):
         self.test_baseline_6_editing()
 
-    @profiling.function_call_count(2641, {'2.4': 1673, '2.6+cextension'
+    @profiling.function_call_count(2431, {'2.4': 1673, '2.6+cextension'
                                    : 2502})
     def test_profile_7_multiview(self):
         self.test_baseline_7_multiview()
index ba37eaef94cbae4cb4a9f34f595e9ee0a09d2387..c864d271214789051ecc27e1f560eb6f8b52ec1b 100644 (file)
@@ -335,11 +335,11 @@ class ZooMarkTest(TestBase):
     def test_profile_1_create_tables(self):
         self.test_baseline_1_create_tables()
 
-    @profiling.function_call_count(6891)
+    @profiling.function_call_count(6347)
     def test_profile_1a_populate(self):
         self.test_baseline_1a_populate()
 
-    @profiling.function_call_count(481)
+    @profiling.function_call_count(438)
     def test_profile_2_insert(self):
         self.test_baseline_2_insert()
 
@@ -366,7 +366,7 @@ class ZooMarkTest(TestBase):
     def test_profile_5_aggregates(self):
         self.test_baseline_5_aggregates()
 
-    @profiling.function_call_count(2929)
+    @profiling.function_call_count(2774)
     def test_profile_6_editing(self):
         self.test_baseline_6_editing()