optimize sparql.Bindings by FlorianLudwig · Pull Request #1192 · RDFLib/rdflib (original) (raw)

This improves performance 13% on the rdflib-benchmark with the default (memory) store and a store size of 4k.

Moving straight to collections.ChainMap was considered but

  1. Bindings behaves differently when one key is in multiple dicts, as they are iterated over multiple times and also counted on __len__ multiple times
  2. The API is a bit different, increasing the changes size

I do think that the differences for __len__ and __iter__ are unintentional / bugs. If so, I would rework this MR to fix those.