[pypy-svn] r17775 - in pypy/dist/pypy: annotation objspace/std translator
tismer at codespeak.net
tismer at codespeak.net
Fri Sep 23 05:06:02 CEST 2005
Author: tismer
Date: Fri Sep 23 05:05:52 2005
New Revision: 17775
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/policy.py
pypy/dist/pypy/objspace/std/objspace.py
pypy/dist/pypy/translator/ann_override.py
Log:
changed the benchmark to use the latest Python for comparison.
added Samuele's method caching patch. It has some very visible
effect of over 5% for richards and over 6% for pystone.
I would have anyway expected more effect. Maybe the patch
can be extended to catch even more cases, maybe I misunderstood.
Anyway, using 2.5a2 raised the fence for richards, again. I have
to find out, why, again.
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Fri Sep 23 05:05:52 2005
@@ -383,6 +383,7 @@
if x not in self.seen_mutable: # avoid circular reflowing,
# see for example test_circular_mutable_getattr
self.seen_mutable[x] = True
+ self.annotator.policy.event(self, 'mutable', x)
for attr in x.__dict__:
clsdef.add_source_for_attribute(attr, x) # can trigger reflowing
result = SomeInstance(clsdef)
Modified: pypy/dist/pypy/annotation/policy.py
==============================================================================
--- pypy/dist/pypy/annotation/policy.py (original)
+++ pypy/dist/pypy/annotation/policy.py Fri Sep 23 05:05:52 2005
@@ -9,6 +9,9 @@
class BasicAnnotatorPolicy:
allow_someobjects = True
+
+ def event(pol, bookkeeper, what, *args):
+ pass
def specialize(pol, bookkeeper, spaceop, func, args, mono):
return None, None
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Fri Sep 23 05:05:52 2005
@@ -356,9 +356,11 @@
def lookup(self, w_obj, name):
w_type = w_obj.getclass(self)
return w_type.lookup(name)
+ lookup._annspecialcase_ = 'specialize:lookup'
def lookup_in_type_where(self, w_type, name):
return w_type.lookup_where(name)
+ lookup_in_type_where._annspecialcase_ = 'specialize:lookup_in_type_where'
def allocate_instance(self, cls, w_subtype):
"""Allocate the memory needed for an instance of an internal or
Modified: pypy/dist/pypy/translator/ann_override.py
==============================================================================
--- pypy/dist/pypy/translator/ann_override.py (original)
+++ pypy/dist/pypy/translator/ann_override.py Fri Sep 23 05:05:52 2005
@@ -9,6 +9,11 @@
class PyPyAnnotatorPolicy(AnnotatorPolicy):
allow_someobjects = False
+ def __init__(pol):
+ pol.lookups = {}
+ pol.lookups_where = {}
+ pol.pypytypes = {}
+
def override__wrap_exception_cls(pol, space, x):
import pypy.objspace.std.typeobject as typeobject
clsdef = getbookkeeper().getclassdef(typeobject.W_TypeObject)
@@ -28,3 +33,104 @@
from pypy.interpreter import pycode
clsdef = getbookkeeper().getclassdef(pycode.PyCode)
return annmodel.SomeInstance(clsdef)
+
+ def attach_lookup(pol, t, attr):
+ cached = "cached_%s" % attr
+ if not t.is_heaptype():
+ setattr(t, cached, t.lookup(attr))
+ return True
+ return False
+
+ def attach_lookup_in_type_where(pol, t, attr):
+ cached = "cached_where_%s" % attr
+ if not t.is_heaptype():
+ setattr(t, cached, t.lookup_where(attr))
+ return True
+ return False
+
+ def consider_lookup(pol, bookkeeper, attr):
+ assert attr not in pol.lookups
+ from pypy.objspace.std import typeobject
+ cached = "cached_%s" % attr
+ clsdef = bookkeeper.getclassdef(typeobject.W_TypeObject)
+ setattr(clsdef.cls, cached, None)
+ clsdef.add_source_for_attribute(cached, clsdef.cls, clsdef)
+ for t in pol.pypytypes:
+ if pol.attach_lookup(t, attr):
+ clsdef.add_source_for_attribute(cached, t)
+ src = CACHED_LOOKUP % {'attr': attr}
+ print src
+ d = {}
+ exec src in d
+ fn = d["lookup_%s" % attr]
+ pol.lookups[attr] = fn
+
+
+ def consider_lookup_in_type_where(pol, bookkeeper, attr):
+ assert attr not in pol.lookups_where
+ from pypy.objspace.std import typeobject
+ cached = "cached_where_%s" % attr
+ clsdef = bookkeeper.getclassdef(typeobject.W_TypeObject)
+ setattr(clsdef.cls, cached, (None, None))
+ clsdef.add_source_for_attribute(cached, clsdef.cls, clsdef)
+ for t in pol.pypytypes:
+ if pol.attach_lookup_in_type_where(t, attr):
+ clsdef.add_source_for_attribute(cached, t)
+ src = CACHED_LOOKUP_IN_TYPE_WHERE % {'attr': attr}
+ print src
+ d = {}
+ exec src in d
+ fn = d["lookup_in_type_where_%s" % attr]
+ pol.lookups_where[attr] = fn
+
+ def specialize__lookup(pol, bookkeeper, mod, spaceop, func, args, mono):
+ (s_space, s_obj, s_name), _ = args.unpack()
+ if s_name.is_constant():
+ attr = s_name.const
+ if attr not in pol.lookups:
+ print "LOOKUP", attr
+ pol.consider_lookup(bookkeeper, attr)
+ return pol.lookups[attr], args
+ else:
+ pol.lookups[None] = True
+ return func, args
+
+ def specialize__lookup_in_type_where(pol, bookkeeper, mod, spaceop, func, args, mono):
+ (s_space, s_obj, s_name), _ = args.unpack()
+ if s_name.is_constant():
+ attr = s_name.const
+ if attr not in pol.lookups_where:
+ print "LOOKUP_IN_TYPE_WHERE", attr
+ pol.consider_lookup_in_type_where(bookkeeper, attr)
+ return pol.lookups_where[attr], args
+ else:
+ pol.lookups_where[None] = True
+ return func, args
+
+ def event(pol, bookkeeper, what, x):
+ from pypy.objspace.std import typeobject
+ if isinstance(x, typeobject.W_TypeObject):
+ pol.pypytypes[x] = True
+ print "TYPE", x
+ for attr in pol.lookups:
+ if attr:
+ pol.attach_lookup(x, attr)
+ for attr in pol.lookups_where:
+ if attr:
+ pol.attach_lookup_in_type_where(x, attr)
+ return
+
+CACHED_LOOKUP = """
+def lookup_%(attr)s(space, w_obj, name):
+ w_type = w_obj.getclass(space)
+ if not w_type.is_heaptype():
+ return w_type.cached_%(attr)s
+ return w_type.lookup("%(attr)s")
+"""
+
+CACHED_LOOKUP_IN_TYPE_WHERE = """
+def lookup_in_type_where_%(attr)s(space, w_type, name):
+ if not w_type.is_heaptype():
+ return w_type.cached_where_%(attr)s
+ return w_type.lookup_where("%(attr)s")
+"""
More information about the Pypy-commit
mailing list