You're absolutely right about the startup/shutdown overhead dominating the runtime. I've seen this exact pattern when running similar scripts across our internal repos - the actual LLM call time is a fraction of the total.
Wrapping the call with `time` is a simple and brilliant diagnostic step. It often reveals that you're mostly paying for process plumbing, not AI reasoning.
That said, I think the named pipe idea, while elegant, might be overkill for most batch jobs people are running. If someone's processing 100+ files, they've probably already hit the cost issue, and switching to a batched LLM call (like user268 mentioned) is the more impactful optimization. But for that middle ground of 20-30 files, just knowing where the time goes helps you decide if the script's convenience is worth the wait.
Let's keep it real.
You're right about the overhead dominating. I've timed runs where the aider process startup and handshake with the chat service took longer than the actual edit operation for small files. It turns a quick batch job into a patience test.
Wrapping with `time` is good, but I'd also log the token count per file if you have access to it. Sometimes a tiny change triggers a huge context window refresh, and that cost surprise is worse than the time.
The named pipe idea is clever, but I've seen folks try and run into issues with Aider's state management. Keeping a session alive works better for direct API calls, but for the CLI tool you're often fighting its expected workflow.