Open greaber opened 4 years ago
Thanks for the report @greaber. As you have identified this as caused by your imports, what you can do to improve things is to delay those imports.
main.py
import hydra
import torch
@hydra.main(config_path="conf", config_name="config")
def main():
pass
if __name__ == '__main__':
main()
main.py
import hydra
@hydra.main(config_path="conf", config_name="config")
def main(cfg):
import train # delay the importing of train to after we have composed the configuraiton
train.train(cfg)
if __name__ == '__main__':
main()
train.py
import torch
def train(cfg):
pass
I see. I guess it could be pretty nice if the completion could use some kind of cache so it doesn't have to do this analysis on every completion, but I understand that would take a significant effort to implement, and it's not something I have time to do.
Yup, running some kind of daemon would be perfect to cache the resulting config object, but as you pointed out this is a major effort and I am not sure it's worth it as this time.
Closing for now.
@Jasha10 There's a new PEP for lazy imports which might be of interest if this gets revisited
Awesome, thanks for the link @addisonklinke.
We can experiment with having our CLI completion hook set the PYTHONLAZYIMPORTS
environment variable or the -L
if the PEP is implemented. It might also be possible for users to opt into faster completion by setting that env variable manually.
I'll reopen this issue so it stays on our radar.
🐛 Bug
Description
Bash tab completion is slow for me (over two seconds even with a trivial config and a moderately complex config adds another 600ms). It seems that the reason is that it is loading my whole script, and some imports are slow.
Checklist
To reproduce
Minimal Code/Config snippet to reproduce
import torch
here is just an example of a slow import.System information
I'm running on a fast machine with ssd, no NFS or anything.