Hi Ben, I am not convinced that combining operations will have a significant impact in term of performance. Mark Shanon implemented that in his HotPy project.
I proposed a RETURN_NONE opcode to combine LOAD_CONST with RETURN_VALUE. The issue was rejected because I failed to show any speedup. https://bugs.python.org/issue28800 I would be interested to restart/finish my registervm project to use register-based bytecode. It allows to implement more optmisations and reduce the number of instructions. In my experience, less instructions = faster code. http://faster-cpython.readthedocs.io/registervm.html Mark's bytecode uses registers but also a stack. Victor Le 24 mai 2017 8:09 PM, "Ben Hoyt" <benh...@gmail.com> a écrit : > Hi folks, > > I was looking at some `dis` output today, and I was wondering if anyone > has investigated optimizing Python (slightly) by adding special-case > bytecodes for common expressions or statements involving constants? > > For example, I (and, based on a quick grep of the stdlib, many others) > write "x is None" and "x is not None" very often. Or "return True" or > "return None" or "return 1" and things like that. These all expand into two > bytecodes, which seems pretty non-optimal (LOAD_CONST + COMPARE_OP or > LOAD_CONST + RETURN_VALUE). It seems we could get an easy speedup for these > common cases by adding a peephole optimization and some new opcodes (maybe > COMPARE_IS_SMALL_CONST and RETURN_SMALL_CONST for these cases). > > I'm not proposing to do this yet, as I'd need to benchmark to see how much > of a gain (if any) it would amount to, but I'm just wondering if there's > any previous work on this kind of thing. Or, if not, any other thoughts > before I try it? > > Thanks, > Ben > > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ > victor.stinner%40gmail.com > >
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com