summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-12 17:50:25 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-12 17:50:25 -0500
commit1125a4b8b1a7b41111396b5b58887047a847b59e (patch)
treee15bda26a23b735a9fbf74d085e5e0e7411c0b84
parentb12caa18b5b05e30078bcd85f48c66cdd17965e7 (diff)
downloadsqlalchemy-1125a4b8b1a7b41111396b5b58887047a847b59e.tar.gz
- another easy win, cache the calc of bind processors in the compiled object
-rw-r--r--lib/sqlalchemy/engine/default.py9
-rw-r--r--lib/sqlalchemy/sql/compiler.py19
-rw-r--r--lib/sqlalchemy/util/_collections.py6
-rw-r--r--test/aaa_profiling/test_resultset.py2
-rw-r--r--test/aaa_profiling/test_zoomark.py2
-rw-r--r--test/aaa_profiling/test_zoomark_orm.py6
6 files changed, 29 insertions, 15 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index 21603b258..22fff3312 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -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
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index eb339cf1d..d5b877a35 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -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
diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py
index 6739c6d09..ef315445d 100644
--- a/lib/sqlalchemy/util/_collections.py
+++ b/lib/sqlalchemy/util/_collections.py
@@ -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)
diff --git a/test/aaa_profiling/test_resultset.py b/test/aaa_profiling/test_resultset.py
index da8653184..f56bfc73e 100644
--- a/test/aaa_profiling/test_resultset.py
+++ b/test/aaa_profiling/test_resultset.py
@@ -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()]
diff --git a/test/aaa_profiling/test_zoomark.py b/test/aaa_profiling/test_zoomark.py
index 85e416184..4bd4c9d09 100644
--- a/test/aaa_profiling/test_zoomark.py
+++ b/test/aaa_profiling/test_zoomark.py
@@ -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()
diff --git a/test/aaa_profiling/test_zoomark_orm.py b/test/aaa_profiling/test_zoomark_orm.py
index ba37eaef9..c864d2712 100644
--- a/test/aaa_profiling/test_zoomark_orm.py
+++ b/test/aaa_profiling/test_zoomark_orm.py
@@ -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()