Skip to content

Instantly share code, notes, and snippets.

@antonagestam
Created March 3, 2024 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonagestam/86f96f3dccee8c8ff7711f9647c5783a to your computer and use it in GitHub Desktop.
Save antonagestam/86f96f3dccee8c8ff7711f9647c5783a to your computer and use it in GitHub Desktop.
Eagerly load all kio modules, takes 2-3s
import kio.schema
from pkgutil import iter_modules
from pkgutil import resolve_name
import time
from pathlib import Path
schema_dir = Path(kio.schema.__file__).parent.resolve()
print(f"{schema_dir=}")
t0 = time.monotonic_ns()
for api_mod in iter_modules([schema_dir]):
api_dir = schema_dir / api_mod.name
for version_mod in iter_modules([api_dir]):
version_dir = api_dir / version_mod.name
for type_mod in iter_modules([version_dir], prefix=f"kio.schema.{api_mod.name}.{version_mod.name}."):
imported = resolve_name(type_mod.name)
# print(f"{imported=}")
t1 = time.monotonic_ns()
d = (t1 - t0) / 1_000_000
print(f"took {d:.2f}ms")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment