disable caching in several places
authorForrest Voight <forrest@forre.st>
Fri, 20 Jan 2012 05:02:55 +0000 (00:02 -0500)
committerForrest Voight <forrest@forre.st>
Fri, 20 Jan 2012 06:11:50 +0000 (01:11 -0500)
p2pool/bitcoin/data.py
p2pool/data.py
p2pool/main.py
p2pool/util/memoize.py [deleted file]
p2pool/util/slush.py [deleted file]

index 06e940e..6bf8a63 100644 (file)
@@ -4,7 +4,7 @@ import hashlib
 import struct
 
 from . import base58
-from p2pool.util import bases, math, expiring_dict, memoize, slush
+from p2pool.util import bases, math
 import p2pool
 
 class EarlyEnd(Exception):
@@ -73,7 +73,7 @@ class Type(object):
         
         return obj
     
-    def pack2(self, obj):
+    def pack(self, obj):
         data = self._pack(obj)
         
         if p2pool.DEBUG:
@@ -82,30 +82,6 @@ class Type(object):
         
         return data
     
-    _backing = None
-    
-    @classmethod
-    def enable_caching(cls):
-        assert cls._backing is None
-        cls._backing = expiring_dict.ExpiringDict(100)
-        cls._pre_pack2 = cls.pack2
-        cls.pack2 = memoize.memoize_with_backing(cls._backing, [cls.unpack])(cls.pack2)
-        cls._pre_unpack = cls.unpack
-        cls.unpack = memoize.memoize_with_backing(cls._backing)(cls.unpack) # doesn't have an inverse
-    
-    @classmethod
-    def disable_caching(cls):
-        assert cls._backing is not None
-        cls._backing.stop()
-        cls._backing = None
-        cls.pack2 = cls._pre_pack2
-        del cls._pre_pack2
-        cls.unpack = cls._pre_unpack
-        del cls._pre_unpack
-    
-    def pack(self, obj):
-        return self.pack2(slush.immutify(obj))
-    
     
     def pack_base58(self, obj):
         return base58.encode(self.pack(obj))
@@ -175,14 +151,14 @@ class PassthruType(Type):
 class EnumType(Type):
     def __init__(self, inner, values):
         self.inner = inner
-        self.values = slush.frozendict(values)
+        self.values = values
         
         keys = {}
         for k, v in values.iteritems():
             if v in keys:
                 raise ValueError('duplicate value in values')
             keys[v] = k
-        self.keys = slush.frozendict(keys)
+        self.keys = keys
     
     def read(self, file):
         data, file = self.inner.read(file)
@@ -406,7 +382,7 @@ address_type = ComposedType([
 tx_type = ComposedType([
     ('version', StructType('<I')),
     ('tx_ins', ListType(ComposedType([
-        ('previous_output', PossiblyNoneType(slush.frozendict(hash=0, index=2**32 - 1), ComposedType([
+        ('previous_output', PossiblyNoneType(dict(hash=0, index=2**32 - 1), ComposedType([
             ('hash', HashType()),
             ('index', StructType('<I')),
         ]))),
index 30a64f0..7d760a0 100644 (file)
@@ -9,7 +9,7 @@ from twisted.python import log
 import p2pool
 from p2pool import skiplists
 from p2pool.bitcoin import data as bitcoin_data, script
-from p2pool.util import memoize, expiring_dict, math, forest
+from p2pool.util import math, forest
 
 
 share_data_type = bitcoin_data.ComposedType([
@@ -417,7 +417,6 @@ class OkayTracker(forest.Tracker):
         
         return best, desired
     
-    @memoize.memoize_with_backing(expiring_dict.ExpiringDict(5, get_touches=False))
     def score(self, share_hash, ht):
         head_height, last = self.verified.get_height_and_last(share_hash)
         score2 = 0
index d5c7259..b2316eb 100644 (file)
@@ -51,8 +51,6 @@ def main(args, net, datadir_path):
             print "Install Pygame and PIL to enable visualizations! Visualizations disabled."
             print
         
-        bitcoin_data.Type.enable_caching()
-        
         # connect to bitcoind over JSON-RPC and do initial getmemorypool
         url = 'http://%s:%i/' % (args.bitcoind_address, args.bitcoind_rpc_port)
         print '''Testing bitcoind RPC connection to '%s' with username '%s'...''' % (url, args.bitcoind_rpc_username)
diff --git a/p2pool/util/memoize.py b/p2pool/util/memoize.py
deleted file mode 100644 (file)
index b5efab2..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-_nothing = object()
-
-def memoize_with_backing(backing, has_inverses=set()):
-    def a(f):
-        def b(*args):
-            res = backing.get((f, args), _nothing)
-            if res is not _nothing:
-                return res
-            
-            res = f(*args)
-            
-            backing[(f, args)] = res
-            for inverse in has_inverses:
-                backing[(inverse, args[:-1] + (res,))] = args[-1]
-            
-            return res
-        return b
-    return a
-
-def memoize(f):
-    return memoize_with_backing({})(f)
diff --git a/p2pool/util/slush.py b/p2pool/util/slush.py
deleted file mode 100644 (file)
index 3bb51e7..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-class frozendict(dict):
-    __slots__ = ['_hash']
-    
-    def __hash__(self):
-        rval = getattr(self, '_hash', None)
-        if rval is None:
-            rval = self._hash = hash(frozenset(self.iteritems()))
-        return rval
-
-class frozenlist(list):
-    __slots__ = ['_hash']
-    
-    def __hash__(self):
-        rval = getattr(self, '_hash', None)
-        if rval is None:
-            rval = self._hash = hash(tuple(self))
-        return rval
-
-def immutify(x):
-    if isinstance(x, list):
-        return frozenlist(immutify(y) for y in x)
-    elif isinstance(x, dict):
-        return frozendict((immutify(k), immutify(v)) for k, v in x.iteritems())
-    else:
-        hash(x) # will throw error if not immutable
-        return x