menelaus icon indicating copy to clipboard operation
menelaus copied to clipboard

Make import statements more efficient

Open tms-bananaquit opened this issue 3 years ago • 1 comments

If a dot-import (np.sqrt) is called, the lookup resolves np first, then sqrt. This doesn't make a big difference except within a for loop, apparently -- and most of the detectors are going to be run within for loops. In that case, it's better to do e.g. from numpy import sqrt instead of import numpy as np.

We might get slightly better performance, then, if we go through update methods and identify eventual calls to dot-imports and replace them with the pattern above.

https://stackoverflow.com/questions/32151193/is-there-a-performance-cost-putting-python-imports-inside-functions

tms-bananaquit avatar Jun 09 '22 20:06 tms-bananaquit

This doesn't seem to make a consistently big difference, just timing a couple runs of KDQTreePartitioner.build. Leaving it for now.

tms-bananaquit avatar Jun 22 '22 17:06 tms-bananaquit