Original article
https://instagram-engineering.com/python-at-scale-strict-modules-c0bb9245c834
term description see
import-time when imports are executed

Sources of slowness

import re
from mywebframework import db, route
VALID_NAME_RE = re.compile("^[a-zA-Z0-9]+$")
@route('/')
def home():
    return "Hello World!"
class Person(db.Model):
    name: str
  • top level scope defines – regex compilation
  • decorator with unknown behaviour
  • class definition: runs code contained within
  • base class may have a meta-class or __init_subclass__ method.

Safety at scale

# fetching config from a network source
MY_CONFIG = get_config_from_network_service()
  • unsafe import side effects