Can the CPython JIT optimise `getattr` with constant arguments?
Discussions on Python.org
Can the CPython JIT optimise `getattr` with constant arguments?
Hi, For the following code: def f(obj: object, attribute: str): return getattr(obj, attribute) for _ in range(1_000_000_000): f(obj, "foo") f(obj, "bar") can the CPython JIT recognise that attribute is always a constant at these call sites, and potentially specialise f() such that the calls become something equivalent to: for _ in range(1_000_000_000): obj.foo obj.bar If so, is there any documentation or way to inspect/verify that this optimisation is happening? Thanks...
0 comments
No comments yet.