engine: route hot-path logs through os.write (fast_print) instead of print()
The engine emits a lot of debug output during generation. Builtin print() goes through a buffered, lock-guarded text stream — per-call overhead plus a lock that can serialize against other threads on the hot path. New codai/api/fastlog.py fast_print writes each line with a single os.write(1) syscall: unbuffered, no Python-level lock, atomic for pipe writes up to PIPE_BUF (log lines don't interleave), with a fallback to real print() for stderr/failures. Imported as print() in the generation hot path: api/text.py, backends/vulkan.py, backends/ cuda.py. Verified: fast_print mirrors print's signature (sep/end/file/flush), writes to fd 1, falls back for stderr; all three modules compile. Co-Authored-By:Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DDv7BchtZQWsnPG6Jm49m
Showing
codai/api/fastlog.py
0 → 100644
Please
register
or
sign in
to comment