Pankaj Pandey added the comment:
I simply profiled the script with "python -m cProfile -s cumtime
inspect_stack_perf.py"
And yes, I should move the linecache check first, that would be a better idea.
Though getmodule() is also fast enough and reordering it does not significantly
Pankaj Pandey added the comment:
Here's the patch performance difference before and after the patch:
Before:
Sun May 20 21:42:32 2018prof1.stat
1188991 function calls (1188851 primitive calls) in 4.821 seconds
Ordered by: cumulative time
ncalls tottime percall cu
New submission from Pankaj Pandey :
The specific os.path.exists() call is shown here:
https://github.com/python/cpython/pull/6805
If the filename is already in linecache or the module has a PEP 302 loader,
then the os.path.exists() call is ignored. Hence it is better to call it only
if its