(no title)
drhagen | 2 months ago
n = 1000
a = {}
for i in range(n):
a[i] = str(i)
a = frozendict(a) # O(n) operation can be turned to O(1)
It is relatively easy for the JIT to detect the `frozendict` constructor, the `dict` input, and the single reference immediately overwritten. Not sure if this would ever be worth it.
_flux|2 months ago
zbentley|2 months ago
There are also potentially other optimizations that could be applied (not specific to dict/frozendict) to reduce the memory overhead on operations like "a = f(a)" for selected values of "f".
zahlman|2 months ago
But actually, I suspect it can't do this optimization simply because the name `frozendict` could be shadowed.
tracnar|2 months ago