Rev 5280: (spiv) Use lazy imports in bzrilb.merge to minimise the startup cost of in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jun 4 06:59:57 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5280 [merge]
revision-id: pqm at pqm.ubuntu.com-20100604055955-98pfcy1bn8oz7749
parent: pqm at pqm.ubuntu.com-20100603031853-rzypooksqjaonb9m
parent: andrew.bennetts at canonical.com-20100604030935-4slnx0e8uh9b8yk6
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-06-04 06:59:55 +0100
message:
  (spiv) Use lazy imports in bzrilb.merge to minimise the startup cost of
   plugins like news_merge. (Andrew Bennetts)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/_annotator_py.py        _annotator_py.py-20090617192546-21fnjrg2s2c16uem-1
  bzrlib/annotate.py             annotate.py-20050922133147-7c60541d2614f022
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
  bzrlib/tests/test_import_tariff.py test_import_tariff.p-20100207155145-ff9infp7goncs7zh-1
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
  bzrlib/textmerge.py            textmerge.py-20060408064938-a5d5c009e64a3a25
  doc/developers/testing.txt     testing.txt-20080812140359-i70zzh6v2z7grqex-1
=== modified file 'NEWS'
--- a/NEWS	2010-06-02 05:03:31 +0000
+++ b/NEWS	2010-06-04 03:09:35 +0000
@@ -32,6 +32,12 @@
 Improvements
 ************
 
+* Use lazy imports in ``bzrlib/merge.py`` so that plugins like ``news_merge``
+  do not cause modules to be loaded unnecessarily just because the plugin
+  registers a merge hook.  This improves ``bzr rocks`` time by about 25%
+  in a default installation (with just the core plugins).
+  (Andrew Bennetts)
+
 Documentation
 *************
 
@@ -44,6 +50,11 @@
 API Changes
 ***********
 
+* ``bzrlib.knit.KnitSequenceMatcher``, which has been deprecated since
+  2007, has been deleted.  Use ``PatienceSequenceMatcher`` from
+  ``bzrlib.patiencediff`` instead.
+  (Andrew Bennetts)
+
 Internals
 *********
 

=== modified file 'bzrlib/_annotator_py.py'
--- a/bzrlib/_annotator_py.py	2009-07-08 23:10:47 +0000
+++ b/bzrlib/_annotator_py.py	2010-06-04 03:09:35 +0000
@@ -18,13 +18,15 @@
 
 from bzrlib.lazy_import import lazy_import
 lazy_import(globals(), """
-from bzrlib import annotate # Must be lazy to avoid circular importing
+from bzrlib import (
+    annotate, # Must be lazy to avoid circular importing
+    graph as _mod_graph,
+    patiencediff,
+    )
 """)
 from bzrlib import (
     errors,
-    graph as _mod_graph,
     osutils,
-    patiencediff,
     ui,
     )
 

=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py	2009-09-14 01:48:28 +0000
+++ b/bzrlib/annotate.py	2010-06-04 03:09:35 +0000
@@ -28,11 +28,16 @@
 import sys
 import time
 
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
+from bzrlib import (
+    patiencediff,
+    tsort,
+    )
+""")
 from bzrlib import (
     errors,
     osutils,
-    patiencediff,
-    tsort,
     )
 from bzrlib.config import extract_email_address
 from bzrlib.repository import _strip_NULL_ghosts
@@ -312,8 +317,7 @@
 
 
 def _get_matching_blocks(old, new):
-    matcher = patiencediff.PatienceSequenceMatcher(None,
-        old, new)
+    matcher = patiencediff.PatienceSequenceMatcher(None, old, new)
     return matcher.get_matching_blocks()
 
 

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2010-05-14 13:25:05 +0000
+++ b/bzrlib/knit.py	2010-06-04 03:09:35 +0000
@@ -68,6 +68,7 @@
     index as _mod_index,
     lru_cache,
     pack,
+    patiencediff,
     progress,
     static_tuple,
     trace,
@@ -79,7 +80,6 @@
 from bzrlib import (
     errors,
     osutils,
-    patiencediff,
     )
 from bzrlib.errors import (
     FileExists,
@@ -3417,10 +3417,6 @@
             raise exc_class, exc_value, exc_traceback
 
 
-# Deprecated, use PatienceSequenceMatcher instead
-KnitSequenceMatcher = patiencediff.PatienceSequenceMatcher
-
-
 def annotate_knit(knit, revision_id):
     """Annotate a knit with no cached annotations.
 

=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py	2010-05-25 17:27:52 +0000
+++ b/bzrlib/merge.py	2010-06-04 03:09:35 +0000
@@ -16,14 +16,14 @@
 
 import warnings
 
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
 from bzrlib import (
     branch as _mod_branch,
     conflicts as _mod_conflicts,
     debug,
-    decorators,
     errors,
     graph as _mod_graph,
-    hooks,
     merge3,
     osutils,
     patiencediff,
@@ -34,9 +34,14 @@
     tree as _mod_tree,
     tsort,
     ui,
-    versionedfile
+    versionedfile,
     )
 from bzrlib.cleanup import OperationWithCleanups
+""")
+from bzrlib import (
+    decorators,
+    hooks,
+    )
 from bzrlib.symbol_versioning import (
     deprecated_in,
     deprecated_method,

=== modified file 'bzrlib/tests/test_import_tariff.py'
--- a/bzrlib/tests/test_import_tariff.py	2010-05-31 01:28:29 +0000
+++ b/bzrlib/tests/test_import_tariff.py	2010-06-04 03:09:35 +0000
@@ -93,9 +93,12 @@
             'bzrlib.bundle.commands',
             'bzrlib.cmd_version_info',
             'bzrlib.foreign',
+            'bzrlib.merge3',
+            'bzrlib.patiencediff',
             'bzrlib.remote',
             'bzrlib.sign_my_commits',
             'bzrlib.smart',
+            'bzrlib.transform',
             'kerberos',
             'smtplib',
             'tarfile',

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2010-02-23 07:43:11 +0000
+++ b/bzrlib/tests/test_knit.py	2010-06-04 03:09:35 +0000
@@ -17,30 +17,25 @@
 """Tests for Knit data structure"""
 
 from cStringIO import StringIO
-import difflib
-import gzip
 import sys
 
 from bzrlib import (
     errors,
-    generate_ids,
     knit,
     multiparent,
     osutils,
     pack,
     tests,
+    tuned_gzip,
     )
 from bzrlib.errors import (
-    RevisionAlreadyPresent,
     KnitHeaderError,
-    RevisionNotPresent,
     NoSuchFile,
     )
 from bzrlib.index import *
 from bzrlib.knit import (
     AnnotatedKnitContent,
     KnitContent,
-    KnitSequenceMatcher,
     KnitVersionedFiles,
     PlainKnitContent,
     _VFContentMapGenerator,
@@ -50,18 +45,15 @@
     _KnitKeyAccess,
     make_file_factory,
     )
+from bzrlib.patiencediff import PatienceSequenceMatcher
 from bzrlib.repofmt import pack_repo
 from bzrlib.tests import (
-    Feature,
-    KnownFailure,
     TestCase,
     TestCaseWithMemoryTransport,
     TestCaseWithTransport,
     TestNotApplicable,
     )
 from bzrlib.transport import get_transport
-from bzrlib.transport.memory import MemoryTransport
-from bzrlib.tuned_gzip import GzipFile
 from bzrlib.versionedfile import (
     AbsentContentFactory,
     ConstantMapper,
@@ -106,8 +98,8 @@
         line_delta = source_content.line_delta(target_content)
         delta_blocks = list(KnitContent.get_line_delta_blocks(line_delta,
             source_lines, target_lines))
-        matcher = KnitSequenceMatcher(None, source_lines, target_lines)
-        matcher_blocks = list(list(matcher.get_matching_blocks()))
+        matcher = PatienceSequenceMatcher(None, source_lines, target_lines)
+        matcher_blocks = list(matcher.get_matching_blocks())
         self.assertEqual(matcher_blocks, delta_blocks)
 
     def test_get_line_delta_blocks(self):
@@ -700,7 +692,7 @@
 
     def create_gz_content(self, text):
         sio = StringIO()
-        gz_file = gzip.GzipFile(mode='wb', fileobj=sio)
+        gz_file = tuned_gzip.GzipFile(mode='wb', fileobj=sio)
         gz_file.write(text)
         gz_file.close()
         return sio.getvalue()

=== modified file 'bzrlib/textmerge.py'
--- a/bzrlib/textmerge.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/textmerge.py	2010-06-04 03:09:35 +0000
@@ -18,7 +18,10 @@
 #         Aaron Bentley <aaron.bentley at utoronto.ca>
 
 
-import bzrlib.patiencediff
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
+from bzrlib import patiencediff
+""")
 
 
 class TextMerge(object):
@@ -131,7 +134,8 @@
         """Return structured merge info.
         See TextMerge docstring.
         """
-        sm = bzrlib.patiencediff.PatienceSequenceMatcher(None, self.lines_a, self.lines_b)
+        sm = patiencediff.PatienceSequenceMatcher(
+            None, self.lines_a, self.lines_b)
         pos_a = 0
         pos_b = 0
         for ai, bi, l in sm.get_matching_blocks():

=== modified file 'doc/developers/testing.txt'
--- a/doc/developers/testing.txt	2010-05-12 10:51:28 +0000
+++ b/doc/developers/testing.txt	2010-06-04 03:09:35 +0000
@@ -430,7 +430,7 @@
   dependencies and only needed for particular cases.  If they're loaded in
   other cases then bzr may break for people who don't have those modules.
   
-`test_import_tarrif` allows us to check that removal of imports doesn't
+`test_import_tariff` allows us to check that removal of imports doesn't
 regress.
 
 This is done by running the command in a subprocess with




More information about the bazaar-commits mailing list