From: Mike Bayer Date: Sun, 12 Dec 2010 22:50:25 +0000 (-0500) Subject: - another easy win, cache the calc of bind processors in the compiled object X-Git-Tag: rel_0_7b1~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1125a4b8b1a7b41111396b5b58887047a847b59e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - another easy win, cache the calc of bind processors in the compiled object --- diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 21603b2586..22fff33120 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 eb339cf1d4..d5b877a358 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 6739c6d096..ef315445d0 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 da8653184d..f56bfc73e3 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 85e4161840..4bd4c9d09a 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 ba37eaef94..c864d27121 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()