Skip to content

[Performance] Move RecordWriter to Background Worker to Prevent Loop Freezing #48

@DsThakurRawat

Description

@DsThakurRawat

Description

The RecordWriter.write_request call in src/reflex/runtime/server.py (line 2428) is a synchronous, blocking I/O operation called inside an async def handler.

Rationale

Writing large JSONL lines (containing MBs of image base64) and calling flush() synchronously freezes the asyncio event loop. This blocks all concurrent requests and introduces 50-100ms of jitter into the 100Hz robot control loop.

Tasks

  • Refactor RecordWriter to use an internal queue.Queue and a background worker thread.
  • Use loop.run_in_executor or a non-blocking queue push in the /act handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions