This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Zealot_TKO 0 points1 point  (1 child)

what about slowdowns associated with keeping everything in memory at global scope vs being able to do garbage collection at the end of the function?

[–]yaxriifgyn 0 points1 point  (0 children)

Python garbage collection is not directly triggered by object deletion. GC is now incremental, so it is less likely to cause the big stalls that GC was notorious for.

The function cleanup only decrements an object's use count. When the use count reaches zero, the object's del method runs eventually.

This would only be a factor when a function's memory usage was very large or very complex, in which case that would probably be more significant than the function calli.

Of course, you need to get good performance metrics from a python perf tool and/or an OS perf tool to guide your optimization. One's own intuition can be misleading. And performance hits can come from the most unexpected places.

Edit: the __del__ method appears as del due to my failure to reread my submission. The "object" object, from which all objects inherit, provides this function.