4 ms·
Nesting functions like this can have a bad performance impact because functions in Python are objects. Normally, all of those function objects are instantiated
by WoodTree 7y ago
Nesting functions like this can have a bad performance impact because functions in Python are objects. Normally, all of those function objects are instantiated once when you load the module. However nested functions will be instantiated at runtime every time their parent is called, even if they aren’t used. This cost is perceptible in hot paths.
- edflsafoiewq 7y agoAre lambdas different?
- baron816 7y agoI’ve never seen it create a bottle neck, have you?
- weyland108 7y agoIt will definitely be a problem if you use JIT interpreter like pypy
- krallja 7y agoA lambda also behaves this way; it’s how it captures the closure scope.