blog | oilshell.org

Addendum: Two Recurse Center Projects That Explain CPython

2018-03-27

In my last post on Recurse Center, I forgot to mention two projects that pulled me in:

They both have an accompanying article:

I'm really grateful for this work, especially because I know how much effort it takes to write both code and prose.

These projects are so close to work I was already doing that it felt like Recurse Center was a natural fit.

Going Further

They're also a good foundation for understanding this talk:

Excerpts from my notes:

(1) In Python 3.6, bytecode was changed to word code. Instead of encoding each instruction in one or three bytes, depending on whether it has an argument, they're all encoded in two bytes.

(2) Function calls in Python are expensive, and were optimized in two ways:

This snippet shows that it takes four bytecodes to call a method in Python 2.7 (and presumably 3.5):

>>> def f(obj):
...   return obj.method(42)
... 
>>> import dis
>>> dis.dis(f)
  2           0 LOAD_FAST                0 (obj)
              3 LOAD_ATTR                0 (method)
              6 LOAD_CONST               1 (42)
              9 CALL_FUNCTION            1
             12 RETURN_VALUE   

Conclusion

The work on optimization is still in progress, and will be until after my trip, so that's all for now. I wrote a long comment about OPy this morning if you want to follow along more closely.

The next post will flush the blog backlog, as promised in the last post.