[Checkins] [zopefoundation/zope.interface] 6b5502: Move Interface hashing and comparison to C; 2.5 to...

Jason Madden noreply at github.com
Sat Mar 7 01:47:24 CET 2020


  Branch: refs/heads/faster-eq-hash-comparison
  Home:   https://github.com/zopefoundation/zope.interface
  Commit: 6b5502a2f71690a5a6e3deabfba09ab03908d07d
      https://github.com/zopefoundation/zope.interface/commit/6b5502a2f71690a5a6e3deabfba09ab03908d07d
  Author: Jason Madden <jamadden at gmail.com>
  Date:   2020-03-06 (Fri, 06 Mar 2020)

  Changed paths:
    M MANIFEST.in
    A benchmarks/micro.py
    M src/zope/interface/_zope_interface_coptimizations.c
    M src/zope/interface/interface.py
    M src/zope/interface/tests/test_interface.py
    M src/zope/interface/tests/test_sorting.py

  Log Message:
  -----------
  Move Interface hashing and comparison to C; 2.5 to 15x speedup in micro benchmarks

Included benchmark numbers:

Current master, Python 3.8:

.....................
contains (empty dict): Mean +- std dev: 198 ns +- 5 ns
.....................
contains (populated dict): Mean +- std dev: 197 ns +- 6 ns
.....................
contains (populated list): Mean +- std dev: 53.1 us +- 1.2 us

This code:

.....................
contains (empty dict): Mean +- std dev: 77.9 ns +- 2.3 ns
.....................
contains (populated dict): Mean +- std dev: 78.4 ns +- 3.1 ns
.....................
contains (populated list): Mean +- std dev: 3.69 us +- 0.08 us

So anywhere from 2.5 to 15x faster. Not sure how that will translate to
larger benchmarks, but I'm hopeful.

It turns out that messing with ``__module__`` is nasty, tricky
business, especially when you do it from C. Everytime you define a new
subclass, the descriptors that you set get overridden by the type
machinery (PyType_Ready). I'm using a data descriptor and a meta class
right now to avoid that but I'm not super happy with that and would
like to find a better way. (At least, maybe the data part of the
descriptor isn't necessary?) It may be needed to move more code into
C, I don't want a slowdown accessing ``__module__`` either; copying
around the standard PyGetSet or PyMember descriptors isn't enough
because they don't work on the class object (so
``classImplements(InterfaceClass, IInterface)`` fails).




More information about the checkins mailing list