Author: Alex Gaynor <[email protected]>
Branch: 
Changeset: r64629:21a05f62d97f
Date: 2013-05-28 10:08 -0700
http://bitbucket.org/pypy/pypy/changeset/21a05f62d97f/

Log:    Merged logging-perf branch.

        This speeds up logging in many (all?) cases by unrolling
        sys._getframe(<constant>) which allows much of the logging code to
        be constant folded. Note that this can still have poor performance
        in the case that something is logged in a long loop, which causes an
        abort due to trace too long. logging traces have a TON of stuff that
        is constant folded in optimizeopt/ which means that their
        unoptimized trace is often an order of magnitude more than their
        optimized length.

diff --git a/pypy/module/pypyjit/test_pypy_c/test_getframe.py 
b/pypy/module/pypyjit/test_pypy_c/test_getframe.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/pypyjit/test_pypy_c/test_getframe.py
@@ -0,0 +1,25 @@
+from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC
+
+
+class TestGetFrame(BaseTestPyPyC):
+    def test_getframe_one(self):
+        def main(n):
+            import sys
+
+            i = 0
+            while i < n:
+                assert sys._getframe(0).f_code.co_filename == __file__
+                i += 1
+            return i
+
+        log = self.run(main, [300])
+        assert log.result == 300
+        loop, = log.loops_by_filename(self.filepath)
+        assert loop.match("""
+        i54 = int_lt(i47, i28)
+        guard_true(i54, descr=...)
+        guard_not_invalidated(descr=...)
+        i55 = int_add(i47, 1)
+        --TICK--
+        jump(..., descr=...)
+        """)
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -1,14 +1,18 @@
 """
 Implementation of interpreter-level 'sys' routines.
 """
-from pypy.interpreter import gateway
-from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
+
 from rpython.rlib import jit
 from rpython.rlib.runicode import MAXUNICODE
 
+from pypy.interpreter import gateway
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.gateway import unwrap_spec
+
+
 # ____________________________________________________________
 
+
 @unwrap_spec(depth=int)
 def _getframe(space, depth=0):
     """Return a frame object from the call stack.  If optional integer depth is
@@ -21,6 +25,11 @@
     if depth < 0:
         raise OperationError(space.w_ValueError,
                              space.wrap("frame index must not be negative"))
+    return getframe(space, depth)
+
+
[email protected]_inside_iff(lambda space, depth: jit.isconstant(depth))
+def getframe(space, depth):
     ec = space.getexecutioncontext()
     f = ec.gettopframe_nohidden()
     while True:
@@ -28,11 +37,11 @@
             raise OperationError(space.w_ValueError,
                                  space.wrap("call stack is not deep enough"))
         if depth == 0:
-            break
+            f.mark_as_escaped()
+            return space.wrap(f)
         depth -= 1
         f = ec.getnextframe_nohidden(f)
-    f.mark_as_escaped()
-    return space.wrap(f)
+
 
 @unwrap_spec(new_limit="c_int")
 def setrecursionlimit(space, new_limit):
diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py 
b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -156,7 +156,7 @@
             iteritems = self._fields.iteritems()
             if not we_are_translated(): #random order is fine, except for tests
                 iteritems = list(iteritems)
-                iteritems.sort(key = lambda (x,y): x.sort_key())
+                iteritems.sort(key=lambda (x, y): x.sort_key())
             for ofs, value in iteritems:
                 if value.is_null():
                     continue
diff --git a/rpython/jit/metainterp/pyjitpl.py 
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1158,6 +1158,7 @@
         obj = box.getref_base()
         vref = vrefinfo.virtual_ref_during_tracing(obj)
         resbox = history.BoxPtr(vref)
+        self.metainterp.heapcache.new(resbox)
         cindex = history.ConstInt(len(metainterp.virtualref_boxes) // 2)
         metainterp.history.record(rop.VIRTUAL_REF, [box, cindex], resbox)
         # Note: we allocate a JIT_VIRTUAL_REF here
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to