Comment by necovek

Comment by necovek 7 days ago

0 replies

Since the entire evaluation and running is dynamic, you don't need to import (and thus evaluate) a module in certain branches.

Eg. that `if __name__` trick is used to allow a module to be both a runnable script and importable module.

Top it off with plenty of common libraries being dog-slow to import because they are doing some of the anti-pattern stuff too, and you end up executing a lot of code when you just want to import a single module.

Eg. I've seen large Python projects that take 75s just importing all the modules because they are listing imports at the top, and many are executing code during import — imagine wanting to run a simple unit test, and your test runner takes 75s just to get to the point where it can run that 0.01s test for your "quick" TDD iteration.

You can also look at Instagram's approach to solving this over at their engineering blog.