GS/64 Performance Improvement on #auditIndexes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

GS/64 Performance Improvement on #auditIndexes

Norm Green-2
The following code may give a substantial improvement in the performance of the #auditIndexes method on UnorderedCollection.  The code below is for GS/64 2.x ; the code for v3.0 is slightly different (email me if you want it).  This code has been through some testing but has NOT been formally QA-certified.  That's a long way of saying "use at your own risk".  But since it's only an audit the risk should be very low.

Norm

P.S. : Hope to see everyone in a few weeks at Smalltalk Solutions in Vegas



File in and commit as SystemUser.


! Fix 41291 - don't use #_indexOfIdentical: in here.
category: 'Audit'
method: BtreeNode
auditNsc: nsc for: pathTerm offset: offset on: aString

"Verifies that the btree structure consistent relative to the given pathTerm."

| indicatesIndexOnNscElements count key value bag ivOffset bagOfKeys setOfKeys |

indicatesIndexOnNscElements := pathTerm indicatesIndexOnNscElements.
count := 0.
bag := IdentityBag new.
bagOfKeys := IdentityBag new.
setOfKeys := IdentitySet new.

self _auditLeafKeysValuesAndEncryptedDo:  [:k :v :encryptedEntry :encryptedKey|
  encryptedEntry ~~ nil
    ifTrue: [
      encryptedEntry = encryptedKey
        ifFalse: [
          pathTerm auditInfo: #[ k, nil, nil ] on: aString.
          aString add: 'Btree [';
            add: self asOop asString;
            add: '] has encryptedKey for [';
            add: v asOop asString;
            add: '] of class ';
            add: v class asString;
            add: ' associated with key [';
            add: k asOop asString;
            add: '] that is [';
            add: (encryptedEntry at: 1) asOop asString;
            add: ', ';
            add: (encryptedEntry at: 2) asOop asString;
            add: '] but should be [';
            add: (encryptedKey at: 1) asOop asString;
            add: ', ';
            add: (encryptedKey at: 2) asOop asString;
            add: ']';
            add: Character lf.
        ]].
  count := count + 1.
  indicatesIndexOnNscElements
    ifTrue: [
      (v == k)
        ifFalse: [
          pathTerm auditInfo: #[ k, nil, nil ] on: aString.
          aString add: 'Btree [';
            add: self asOop asString;
            add: '] has entry for [';
            add: v asOop asString;
            add: '] of class ';
            add: v class asString;
            add: ' associated with incorrect key [';
            add: k asOop asString;
            add: '] should be ( ';
            add:  v asOop asString;
            add: ') ';
            add: Character lf.
        ].
    ]
    ifFalse: [
      ivOffset := (pathTerm _ivOffsetFor: v).
      ((v instVarAt: ivOffset) == k)
        ifFalse: [
          pathTerm auditInfo: #[ k, nil, nil ] on: aString.
          aString add: 'Btree [';
            add: self asOop asString;
            add: '] has entry for [';
            add: v asOop asString;
            add: '] of class ';
            add: v class asString;
            add: ' associated with incorrect key [';
            add: k asOop asString;
            add: '] should be ( ';
            add:  (v instVarAt: ivOffset) asOop asString;
            add: ') ';
            add: Character lf.
      ].
    ].
  (count > 1)
    ifTrue: [
      (value == v)
        ifFalse: [
          self _auditKey: key
                value: value
                bag: bag
                nsc: nsc
                for: pathTerm
                offset: offset
                on: aString.
        ].
      (BtreeComparisonForSort compareKey: key equalTo: k)
        ifTrue: [
          bagOfKeys add: k.
          setOfKeys add: k.
        ]
        ifFalse: [
          1 to: setOfKeys size do:[:n| |aKey|
            aKey := setOfKeys at: n.
            (DependencyList for: aKey) ~~ nil
              ifTrue:[  pathTerm auditDepListForByteObject: aKey
                                 occurrences: (bagOfKeys occurrencesOf: aKey)
                                 index: (pathTerm at: offset)
                                 on: aString .
              ].
           ].
          bagOfKeys removeAll: bagOfKeys.
          setOfKeys removeAll: setOfKeys.
          bagOfKeys add: k.
          setOfKeys add: k.
        ].

    ]
    ifFalse: [
          bagOfKeys add: k.
          setOfKeys add: k.
    ].
  value := v.
  key := k.
  bag add: v.
].
self _auditKey: key
       value: value
       bag: bag
       nsc: nsc
       for: pathTerm
       offset: offset
       on: aString.

1 to: setOfKeys size do:[:n| |aKey|
  aKey := setOfKeys at: n.
  (DependencyList for: aKey) ~~ nil
    ifTrue: [ pathTerm auditDepListForByteObject: aKey
                       occurrences: (bagOfKeys occurrencesOf: aKey)
                       index: (pathTerm at: offset)
                       on: aString.
    ].
].

^count
%