Skip to content

Multiprocessing Overhead Explanation

Note: netherframe has since replaced Loguru with structlog + stdlib logging.handlers.QueueListener over an in-memory queue.SimpleQueue, eliminating Loguru's multiprocessing.Queue writer thread and recv_bytes profiling artifact. The historical investigation below is kept for context.

The Mystery Solved

The 860ms "multiprocessing overhead" from recv_bytes is not actually slowing down synthesis. Here's what's really happening:

1. Loguru's Background Thread

When enqueue=True (the default), Loguru creates a daemon thread called loguru-writer-1 that: - Uses a multiprocessing.Queue internally (even for single-process scenarios) - Processes log messages asynchronously in the background - Continues running after the main work is done

2. Profiling Artifact

The profiling shows 860ms in recv_bytes because: - The profiler captures all thread activity until the program exits - The Loguru background thread is sitting in queue.get() → recv_bytes() waiting for messages - This is just idle waiting time, not actual work

3. Proof It's Not Impacting Performance

Our tests show: - Synthesis completes in 35-382ms (depending on resource count) - The same synthesis performance whether logging is enabled or disabled - The "overhead" only appears when we wait for threads to finish

4. Why It Shows Up in Profiling

# The background thread is doing this:
while True:
    message = queue.get()  # Calls recv_bytes internally
    # This blocks waiting for log messages
    # Shows up as 860ms of "time" but it's just waiting

5. Real Impact

  • During synthesis: ZERO impact (thread is just waiting)
  • Memory: Minimal (one thread + small queue)
  • After synthesis: Thread cleans up when program exits

Conclusion

This is a false alarm! The multiprocessing overhead is: 1. Not affecting synthesis performance at all 2. Just the profiler measuring idle thread wait time 3. A normal part of Loguru's thread-safe architecture

Our actual synthesis performance of 26,204 resources/second is real and not impacted by this background thread activity.