◐ Shell
clean mode source ↗

bpo-42064: Optimise `sqlite3` state access, part 1 by erlend-aasland · Pull Request #27273 · python/cpython

Have you thought about caching the state on Connection objects? That way you could get the state from a cursor by following two pointers. (And similarly for other cases where you have a Connection, which is most of pysqlite).
Connections are already quite heavy, so adding one more pointer might be a good trade-off.

Yes, I have though about it, but I don't remember why I didn't follow that idea :) As you say, it's probably a very good trade-off. I'll have a go at it.

pysqlite_get_state_by_cls looks like it'll eventually use _PyType_GetModuleByDef, which isn't as fast as following two pointers.

Both true. No, it was meant to use PyType_GetModuleState.