Original article
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]+$")
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