2.5 KiB
Prompt
From ai/prompt-io/prompts/issue_470.md:
attempt to resolve https://github.com/goodboy/tractor/issues/470 do it with /open-wkt, ensure you /run-tests on all changes
(plus a hard pause-for-human-review deadline of 12:50PM EST.)
Issue #470 asks to trim the ~0.42s import tractor cost — which dominates per-actor spawn latency on the trio backend — by lazy-importing heavy/optional deps (pdbp, stackscope, multiaddr, + audit of colorlog/bidict/wrapt/setproctitle).
Response summary
Profiling showed the issue’s dep-list only accounted for ~20ms; the dominant cost (~244ms) was log.get_logger()’s get_caller_mod() calling inspect.stack() at module level in ~39 modules — each call walks every stack frame (deep during nested imports) and scans sys.modules per frame via inspect.getmodule().
Changes, in impact order:
get_caller_mod()->sys._getframe()+f_globals['__name__']sys.moduleslookup (~240ms saved).- Issue’s lazy-import checklist:
bidict,multiaddr,colorlog,wraptmoved toTYPE_CHECKING/function-local imports;platformdirsfunction-local;asyncio+.to_asynciodeferred out of thedevx.debug+spawn._entryeager paths (~15ms saved). - PEP 562
__getattr__ontractor/__init__.pypreserving publictractor.to_asyncioattr access.
Results: import tractor 0.42s -> ~0.145s (~65%); sequential start_actor latency 0.40-0.44s -> ~0.179s/actor. pdbp (needs _repl.py class-base restructure) + platformdirs (needs UDSAddress.def_bindspace protocol rework) documented as follow-ups.
Files changed
tractor/log.py—get_caller_mod()perf fix + lazycolorlogtractor/__init__.py— PEP 562 lazyto_asynciotractor/discovery/_addr.py—bidict->TYPE_CHECKINGtractor/discovery/_multiaddr.py— lazymultiaddrtractor/ipc/_tcp.py,tractor/ipc/_uds.py—Multiaddr->TYPE_CHECKINGtractor/runtime/_state.py— lazyplatformdirstractor/devx/_frame_stack.py— lazypdbp+wrapttractor/devx/debug/_trace.py,tractor/devx/debug/_tty_lock.py— lazyasyncio+.to_asynciotractor/spawn/_entry.py— lazyrun_as_asyncio_guest
Human edits
None yet — pending user review at the 12:50PM EST pause gate (test-suite results reported in-session).