Added caching to SCMAbstractPackageModel to speed up certain queries.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sat, 01 Mar 2014 00:22:00 +0000
changeset 388 d093d603292a
parent 387 ebec1ef28839
child 389 1e2e6ce45878
Added caching to SCMAbstractPackageModel to speed up certain queries. Package model now caches values of #isVirtual, #classesHasChanged, #extensionHasChanged and #children. The cache is invalidated when cached sequence number differ from the one returned by SCMCodeMonitor. This fixes performance problems when commiting nested virtual packages.
common/Make.proto
common/Make.spec
common/SCMAbstractPackageModel.st
common/SCMCodeMonitor.st
common/abbrev.stc
common/bc.mak
common/common.rc
common/libInit.cc
common/stx_libscm_common.st
mercurial/mercurial.rc
--- a/common/Make.proto	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/Make.proto	Sat Mar 01 00:22:00 2014 +0000
@@ -152,6 +152,7 @@
 $(OUTDIR)SCMAbstractPackageModelRegistry.$(O) SCMAbstractPackageModelRegistry.$(H): SCMAbstractPackageModelRegistry.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)SCMAbstractSourceCodeManager.$(O) SCMAbstractSourceCodeManager.$(H): SCMAbstractSourceCodeManager.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libbasic3/AbstractSourceCodeManager.$(H) $(STCHDR)
 $(OUTDIR)SCMAbstractTask.$(O) SCMAbstractTask.$(H): SCMAbstractTask.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
+$(OUTDIR)SCMCodeMonitor.$(O) SCMCodeMonitor.$(H): SCMCodeMonitor.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)SCMCommonPackageModelGroup.$(O) SCMCommonPackageModelGroup.$(H): SCMCommonPackageModelGroup.st $(INCLUDE_TOP)/stx/libbasic/Collection.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)SCMCommonSourceCodeManagerUtilities.$(O) SCMCommonSourceCodeManagerUtilities.$(H): SCMCommonSourceCodeManagerUtilities.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libbasic3/SourceCodeManagerUtilities.$(H) $(STCHDR)
 $(OUTDIR)SCMCompatModeQuery.$(O) SCMCompatModeQuery.$(H): SCMCompatModeQuery.st $(INCLUDE_TOP)/stx/libbasic/GenericException.$(H) $(INCLUDE_TOP)/stx/libbasic/Notification.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libbasic/Query.$(H) $(STCHDR)
--- a/common/Make.spec	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/Make.spec	Sat Mar 01 00:22:00 2014 +0000
@@ -55,6 +55,7 @@
 	SCMAbstractPackageModelRegistry \
 	SCMAbstractSourceCodeManager \
 	SCMAbstractTask \
+	SCMCodeMonitor \
 	SCMCommonPackageModelGroup \
 	SCMCommonSourceCodeManagerUtilities \
 	SCMCompatModeQuery \
@@ -72,6 +73,7 @@
     $(OUTDIR_SLASH)SCMAbstractPackageModelRegistry.$(O) \
     $(OUTDIR_SLASH)SCMAbstractSourceCodeManager.$(O) \
     $(OUTDIR_SLASH)SCMAbstractTask.$(O) \
+    $(OUTDIR_SLASH)SCMCodeMonitor.$(O) \
     $(OUTDIR_SLASH)SCMCommonPackageModelGroup.$(O) \
     $(OUTDIR_SLASH)SCMCommonSourceCodeManagerUtilities.$(O) \
     $(OUTDIR_SLASH)SCMCompatModeQuery.$(O) \
--- a/common/SCMAbstractPackageModel.st	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/SCMAbstractPackageModel.st	Sat Mar 01 00:22:00 2014 +0000
@@ -20,7 +20,8 @@
 
 Object subclass:#SCMAbstractPackageModel
 	instanceVariableNames:'name parent children repository repositoryRoot wc wcroot
-		classesHasChanged extensionsHasChanged'
+		classesHasChanged extensionsHasChanged virtual lastSequenceNumber
+		lastSequenceNumberForChildren'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SCM-Common-StX'
@@ -470,22 +471,15 @@
 children
     "Returns all my immediate children."
 
-    | childNames nameSizePlus1 |
-
-    nameSizePlus1 := name size + 1.
-    childNames := Smalltalk allLoadedProjectIDs select:[:each |
-        (each startsWith: name)
-        and:[ each ~= name
-        and:[ ((each at: nameSizePlus1) == $/ or:[ (each at: nameSizePlus1) == $: ])
-        and:[ (each indexOf: $/ startingAt: nameSizePlus1 + 1) == 0]]]].
-    ^ childNames collect:[:each |  self childNamed: (each copyFrom: nameSizePlus1 + 1) ].
+    self updateCachedValues.
+    ^ children values.
 
     "
     (HGPackageModelRegistry packageNamed: 'stx:libscm') children
     "
 
     "Created: / 19-02-2014 / 23:43:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 28-02-2014 / 10:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-02-2014 / 23:54:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 childrenDo: aBlock
@@ -795,29 +789,25 @@
     "Created: / 13-08-2009 / 10:23:19 / Jan Vrany <vranyj1@fel.cvut.cz>"
     "Modified: / 15-11-2012 / 10:05:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified (comment): / 23-11-2012 / 22:50:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!SCMAbstractPackageModel methodsFor:'queries'!
-
-classesHasChanged
-    classesHasChanged :=
-        (classesHasChanged == true) or:[self computeClassesHasChanged].
-
-    ^ classesHasChanged
-
-    "Created: / 06-10-2012 / 23:16:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-extensionsHasChanged
-    extensionsHasChanged :=
-        (extensionsHasChanged == true) or:[self computeExtensionsHasChanged].
+computeChildren
+    | childNames nameSizePlus1 |
 
-    ^ extensionsHasChanged
+    nameSizePlus1 := name size + 1.
+    childNames := Smalltalk allLoadedProjectIDs select:[:each |
+        (each startsWith: name)
+        and:[ each ~= name
+        and:[ ((each at: nameSizePlus1) == $/ or:[ (each at: nameSizePlus1) == $: ])
+        and:[ (each indexOf: $/ startingAt: nameSizePlus1 + 1) == 0]]]].
+    childNames do:[:each |  self childNamed: (each copyFrom: nameSizePlus1 + 1) ].
 
-    "Created: / 06-10-2012 / 23:16:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
+    "
+    (HGPackageModelRegistry packageNamed: 'stx:libscm') children
+    "
 
-!SCMAbstractPackageModel methodsFor:'queries-privacy'!
+    "Created: / 28-02-2014 / 23:53:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
 computeClassesHasChanged
     "
@@ -887,6 +877,56 @@
 
     "Created: / 06-10-2012 / 23:17:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified (format): / 19-03-2013 / 10:12:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+computeIsVirtual
+    "raise an error: this method should be implemented (TODO)"
+
+    ^ self classes isEmpty and:[ self extensions isEmpty ].
+
+    "Created: / 28-02-2014 / 23:46:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+updateCachedValues
+    "Update all cached data"
+
+    | sequenceNumber |
+
+    sequenceNumber := SCMCodeMonitor sequenceNumber.     
+    sequenceNumber ~~ lastSequenceNumber ifTrue:[ 
+        lastSequenceNumber := sequenceNumber.
+        virtual := self computeIsVirtual.
+        virtual ifTrue:[
+            classesHasChanged := false.
+            extensionsHasChanged := false.
+        ] ifFalse:[ 
+            classesHasChanged := (classesHasChanged == true) or:[ self computeClassesHasChanged ].
+            extensionsHasChanged := (extensionsHasChanged == true) or:[ self computeExtensionsHasChanged ].
+        ].
+        self computeChildren.
+    ].
+
+    "Created: / 28-02-2014 / 23:46:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SCMAbstractPackageModel methodsFor:'queries'!
+
+classesHasChanged
+
+    self updateCachedValues.
+    ^ classesHasChanged
+
+    "Created: / 06-10-2012 / 23:16:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-02-2014 / 23:51:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+extensionsHasChanged
+
+    self updateCachedValues.
+    ^ extensionsHasChanged
+
+    "Created: / 06-10-2012 / 23:16:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-02-2014 / 23:51:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SCMAbstractPackageModel methodsFor:'testing'!
@@ -914,9 +954,8 @@
 
      Virtual packages serves merely as containers for nested packages"
 
-    "/ Following implementation is bit time-costly. Maybe we should cache
-    "/ the information. We'll see.
-    ^ self classes isEmpty and:[ self extensions isEmpty ]
+    self updateCachedValues.
+    ^ virtual
 
     "
     (HGPackageModel named: 'stx:libscm') isVirtual
@@ -924,6 +963,7 @@
     "
 
     "Created: / 27-02-2014 / 22:46:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-02-2014 / 23:50:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SCMAbstractPackageModel methodsFor:'utilities'!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/SCMCodeMonitor.st	Sat Mar 01 00:22:00 2014 +0000
@@ -0,0 +1,147 @@
+"
+stx:libscm - a new source code management library for Smalltalk/X
+Copyright (C) 2012-2013 Jan Vrany
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License. 
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+"
+"{ Package: 'stx:libscm/common' }"
+
+Object subclass:#SCMCodeMonitor
+	instanceVariableNames:'sequenceNumber'
+	classVariableNames:'Current SequenceNumberMax'
+	poolDictionaries:''
+	category:'SCM-Common-StX'
+!
+
+!SCMCodeMonitor class methodsFor:'documentation'!
+
+copyright
+"
+stx:libscm - a new source code management library for Smalltalk/X
+Copyright (C) 2012-2013 Jan Vrany
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License. 
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+"
+!
+
+documentation
+"
+    SCMCodeMonitor is helper class that monitors code changes
+    in Smalltalk. Upon each change (class or method added/removed/moved
+    to package/...) it increases internal sequenceNumber.
+
+    Client may use that sequence number to check whether some
+    cached data are still valid - they should be considered
+    out-of-date if sequence number from monitor differs from
+    sequence number remembered when cached value has been 
+    computed.
+
+    [author:]
+        Jan Vrany <jan.vrany@fit.cvut.cz>
+
+    [instance variables:]
+
+    [class variables:]
+
+    [see also:]
+
+"
+! !
+
+!SCMCodeMonitor class methodsFor:'initialization'!
+
+initialize
+    "Invoked at system start or when the class is dynamically loaded."
+
+    "/ please change as required (and remove this comment)
+
+    SequenceNumberMax := SmallInteger maxVal
+
+    "Modified: / 28-02-2014 / 23:25:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SCMCodeMonitor class methodsFor:'instance creation'!
+
+new
+    "return an initialized instance"
+
+    ^ self basicNew initialize.
+! !
+
+!SCMCodeMonitor class methodsFor:'accessing'!
+
+sequenceNumber
+    Current isNil ifTrue:[ 
+        Current := self new.
+    ].
+    ^ Current sequenceNumber
+
+    "Created: / 28-02-2014 / 23:23:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SCMCodeMonitor methodsFor:'accessing'!
+
+sequenceNumber
+    ^ sequenceNumber
+
+    "Created: / 28-02-2014 / 23:29:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SCMCodeMonitor methodsFor:'change & update'!
+
+update:something with:aParameter from:changedObject
+    "Invoked when an object that I depend upon sends a change notification."
+
+    ((something == #methodInClass) 
+        or:[ something == #projectOrganization
+        or:[ something == #classRemove 
+        or:[ something == #newClass ]]]
+    ) ifTrue:[ 
+        sequenceNumber := sequenceNumber == SequenceNumberMax ifTrue:[0] ifFalse:[sequenceNumber := sequenceNumber + 1].
+        ^ self
+    ].
+    ^ self
+"/    Transcript showCR: '>> ', something
+
+    "Modified: / 01-03-2014 / 00:13:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SCMCodeMonitor methodsFor:'initialization'!
+
+initialize
+    "Invoked when a new instance is created."
+
+    sequenceNumber := 0.
+    Smalltalk addDependent: self.  
+
+    "/ super initialize.   -- commented since inherited method does nothing
+
+    "Modified: / 28-02-2014 / 23:25:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+
+SCMCodeMonitor initialize!
--- a/common/abbrev.stc	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/abbrev.stc	Sat Mar 01 00:22:00 2014 +0000
@@ -6,6 +6,7 @@
 SCMAbstractPackageModelRegistry SCMAbstractPackageModelRegistry stx:libscm/common 'SCM-Common-StX' 1
 SCMAbstractSourceCodeManager SCMAbstractSourceCodeManager stx:libscm/common 'SCM-Common-StX' 2
 SCMAbstractTask SCMAbstractTask stx:libscm/common 'SCM-Common-StX-Tasks' 0
+SCMCodeMonitor SCMCodeMonitor stx:libscm/common 'SCM-Common-StX' 0
 SCMCommonPackageModelGroup SCMCommonPackageModelGroup stx:libscm/common 'SCM-Common-StX' 0
 SCMCommonSourceCodeManagerUtilities SCMCommonSourceCodeManagerUtilities stx:libscm/common 'SCM-Common-StX' 0
 SCMCompatModeQuery SCMCompatModeQuery stx:libscm/common 'SCM-Common-StX' 1
--- a/common/bc.mak	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/bc.mak	Sat Mar 01 00:22:00 2014 +0000
@@ -81,6 +81,7 @@
 $(OUTDIR)SCMAbstractPackageModelRegistry.$(O) SCMAbstractPackageModelRegistry.$(H): SCMAbstractPackageModelRegistry.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)SCMAbstractSourceCodeManager.$(O) SCMAbstractSourceCodeManager.$(H): SCMAbstractSourceCodeManager.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libbasic3\AbstractSourceCodeManager.$(H) $(STCHDR)
 $(OUTDIR)SCMAbstractTask.$(O) SCMAbstractTask.$(H): SCMAbstractTask.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
+$(OUTDIR)SCMCodeMonitor.$(O) SCMCodeMonitor.$(H): SCMCodeMonitor.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)SCMCommonPackageModelGroup.$(O) SCMCommonPackageModelGroup.$(H): SCMCommonPackageModelGroup.st $(INCLUDE_TOP)\stx\libbasic\Collection.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)SCMCommonSourceCodeManagerUtilities.$(O) SCMCommonSourceCodeManagerUtilities.$(H): SCMCommonSourceCodeManagerUtilities.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libbasic3\SourceCodeManagerUtilities.$(H) $(STCHDR)
 $(OUTDIR)SCMCompatModeQuery.$(O) SCMCompatModeQuery.$(H): SCMCompatModeQuery.st $(INCLUDE_TOP)\stx\libbasic\GenericException.$(H) $(INCLUDE_TOP)\stx\libbasic\Notification.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libbasic\Query.$(H) $(STCHDR)
--- a/common/common.rc	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/common.rc	Sat Mar 01 00:22:00 2014 +0000
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "Copyright Jan Vrany 2012\0"
       VALUE "ProductName", "Smalltalk/X SCM Support Library\0"
       VALUE "ProductVersion", "6.2.3.0\0"
-      VALUE "ProductDate", "Fri, 28 Feb 2014 10:32:39 GMT\0"
+      VALUE "ProductDate", "Sat, 01 Mar 2014 00:18:39 GMT\0"
     END
 
   END
--- a/common/libInit.cc	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/libInit.cc	Sat Mar 01 00:22:00 2014 +0000
@@ -32,6 +32,7 @@
 _SCMAbstractPackageModelRegistry_Init(pass,__pRT__,snd);
 _SCMAbstractSourceCodeManager_Init(pass,__pRT__,snd);
 _SCMAbstractTask_Init(pass,__pRT__,snd);
+_SCMCodeMonitor_Init(pass,__pRT__,snd);
 _SCMCommonPackageModelGroup_Init(pass,__pRT__,snd);
 _SCMCommonSourceCodeManagerUtilities_Init(pass,__pRT__,snd);
 _SCMCompatModeQuery_Init(pass,__pRT__,snd);
--- a/common/stx_libscm_common.st	Fri Feb 28 10:47:43 2014 +0000
+++ b/common/stx_libscm_common.st	Sat Mar 01 00:22:00 2014 +0000
@@ -148,6 +148,7 @@
         SCMAbstractPackageModelRegistry
         SCMAbstractSourceCodeManager
         SCMAbstractTask
+        SCMCodeMonitor
         SCMCommonPackageModelGroup
         SCMCommonSourceCodeManagerUtilities
         SCMCompatModeQuery
--- a/mercurial/mercurial.rc	Fri Feb 28 10:47:43 2014 +0000
+++ b/mercurial/mercurial.rc	Sat Mar 01 00:22:00 2014 +0000
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "Copyright Jan Vrany 2012\0"
       VALUE "ProductName", "Smalltalk/X Mercurial Integration\0"
       VALUE "ProductVersion", "6.2.3.0\0"
-      VALUE "ProductDate", "Fri, 28 Feb 2014 10:32:41 GMT\0"
+      VALUE "ProductDate", "Sat, 01 Mar 2014 00:18:37 GMT\0"
     END
 
   END