Skip to content
Commit e2db1b5c authored by Stefy Lanza (nextime / spora )'s avatar Stefy Lanza (nextime / spora )
Browse files

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: default avatarClaude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DDv7BchtZQWsnPG6Jm49m
parent 1b8c1c33
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment