fix: offload sync Pydantic serialization to thread in async write path#1178
fix: offload sync Pydantic serialization to thread in async write path#1178charles-dyfis-net wants to merge 1 commit intoqdrant:devfrom
Conversation
❌ Deploy Preview for poetic-froyo-8baba7 failed.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Some contribution process notes:
|
|
Going to revise this slightly to use |
AsyncPointsApi methods for `upsert_points`, `batch_update`, and `update_vectors` call `_build_for_*` which runs `jsonable_encoder` (-> `model_dump_json`) synchronously before the first `await`. This blocks the event loop for the entire duration of Pydantic serialization, which scales linearly with point count and vector dimensionality. Wrap the sync `_build_for_*` call with `asyncio.to_thread` for these three methods, whose body size is unbounded. The `_build_for_*` methods return an unawaited coroutine object (from the async api_client.request), so the executor runs the serialization in a thread and we await the resulting coroutine back on the event loop. Fixes qdrant#1175
b76b850 to
478165e
Compare
AsyncPointsApi methods for
upsert_points,batch_update, andupdate_vectorscall_build_for_*which runsjsonable_encoder(thus Pydantic'smodel_dump_json) synchronously before the firstawait. This blocks the event loop for the entire duration of Pydantic serialization, which scales with point count and vector dimensionality.Move the sync
_build_for_*call intorun_in_executorfor these three methods (skipping some others where body size is bounded and small). The_build_for_*methods return an unawaited coroutine object (from the async api_client.request), so the executor runs the serialization in a thread and we await the resulting coroutine back on the event loop.Fixes #1175