[pypy-commit] pypy stringbuilder2-perf: Tweak: except in the simplest cases where the ll_builder remains virtual,

arigo noreply at buildbot.pypy.org
Sun Jun 15 21:09:05 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: stringbuilder2-perf
Changeset: r72067:3e094220dc86
Date: 2014-06-15 21:08 +0200
http://bitbucket.org/pypy/pypy/changeset/3e094220dc86/

Log:	Tweak: except in the simplest cases where the ll_builder remains
	virtual, write ll_build() as just a simple residual call

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
@@ -1422,6 +1422,8 @@
             return self.execute_varargs(rop.CALL, allboxes, descr, exc, pure)
 
     def do_conditional_call(self, condbox, funcbox, argboxes, descr, pc):
+        if isinstance(condbox, ConstInt) and condbox.value == 0:
+            return   # so that the heapcache can keep argboxes virtual
         allboxes = self._build_allboxes(funcbox, argboxes, descr)
         effectinfo = descr.get_extra_info()
         assert not effectinfo.check_forces_virtual_or_virtualizable()
diff --git a/rpython/rtyper/lltypesystem/rbuilder.py b/rpython/rtyper/lltypesystem/rbuilder.py
--- a/rpython/rtyper/lltypesystem/rbuilder.py
+++ b/rpython/rtyper/lltypesystem/rbuilder.py
@@ -293,14 +293,13 @@
         return ll_builder.total_size - num_chars_missing_from_last_piece
 
     @staticmethod
+    @jit.look_inside_iff(lambda ll_builder: jit.isvirtual(ll_builder))
     def ll_build(ll_builder):
-        jit.conditional_call(bool(ll_builder.extra_pieces),
-                             BaseStringBuilderRepr._ll_fold_pieces, ll_builder)
-        # Here is the one remaining "unexpected" branch with the JIT.
-        # Too bad, but it seems it's the only reasonable way to support
-        # both virtual builders and avoid-shrink-if-size-doesn't-change
-        final_size = ll_builder.current_pos
-        if final_size != ll_builder.total_size:
+        # NB. usually the JIT doesn't look inside this function; it does
+        # so only in the simplest example where it could virtualize everything
+        if ll_builder.extra_pieces:
+            BaseStringBuilderRepr._ll_fold_pieces(ll_builder)
+        elif ll_builder.current_pos != ll_builder.total_size:
             BaseStringBuilderRepr._ll_shrink_final(ll_builder)
         return ll_builder.current_buf
 


More information about the pypy-commit mailing list