|
|
|
|
|
by pcwalton
3855 days ago
|
|
Singletons are fine, but it's almost always better to lazily initialize them rather than eagerly, to save on startup time. As a bonus, if you have no eager global initialization in your language, you can make import completely side-effect-free, which is a really nice simplification that I wish more languages adopted. |
|
We had a decent sized library at a previous company that pulled in modules that defined huge register maps, wrapped c++ libraries, etc.
I wrapped all imports in a lazy importer that was triggered by the first attribute access. It brought our script startup times from 3 seconds down to a fraction.
Blows me away that this isn't default behavior for ALL modules.