Skip to content

Add libuv-backed MultiUv for event-driven concurrent HTTP transfers - #48

Draft
jiacai2050 with Copilot wants to merge 3 commits into
mainfrom
copilot/integrate-libuv-for-better-perf
Draft

Add libuv-backed MultiUv for event-driven concurrent HTTP transfers#48
jiacai2050 with Copilot wants to merge 3 commits into
mainfrom
copilot/integrate-libuv-for-better-perf

Conversation

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown

The existing Multi interface uses curl_multi_poll — a blocking poll — making it unsuitable for integration with external event loops or high-concurrency workloads. This PR adds MultiUv, which wires libcurl's socket-action API into libuv's epoll/kqueue-based event loop.

New: src/MultiUv.zig

Implements the curl_multi_socket_action integration pattern:

  • CURLMOPT_SOCKETFUNCTION → creates/destroys uv_poll_t handles per curl socket
  • CURLMOPT_TIMERFUNCTION → drives curl's timeout via a shared uv_timer_t
  • CompletionCallback fired per-transfer inside the event loop (no polling loop needed)
  • Heap-allocated (create/destroy) to keep libuv handle addresses stable
const loop = c_uv.uv_default_loop();
var multi = try MultiUv.create(allocator, loop, onComplete, null);
defer multi.destroy();

try multi.addHandle(&easy1);
try multi.addHandle(&easy2);

_ = c_uv.uv_run(loop, c_uv.UV_RUN_DEFAULT); // all transfers run here

Build system (build.zig)

New -Dlibuv=true flag (default: false):

  • Passes has_libuv into build_info; root.zig exports MultiUv as void when disabled, so uv headers are never required without the flag
  • module.linkSystemLibrary("uv", .{}) propagates -luv to all artifacts that import the module
  • Adds run-multi-uv step and libuv check/test targets

src/root.zig

pub const MultiUv = if (build_info.has_libuv) @import("MultiUv.zig") else void;

Dead-branch @import means uv.h is never processed unless the flag is set.

examples/multi_uv.zig

Three concurrent GETs via uv_default_loop() + uv_run(), mirroring the existing multi.zig writer pattern.

Makefile

Adds run-libuv target (zig build run-multi-uv -Dlibuv=true).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 8.8.8.8
    • Triggering command: REDACTED, pid is -1 (packet block)
  • ziglang.org
    • Triggering command: /usr/bin/curl curl -s REDACTED --output /tmp/zig-0.15.2.tar.xz (dns block)
    • Triggering command: /usr/bin/ping ping -c 1 ziglang.org (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Integrate with libuv for better perf</issue_title>
<issue_description>https://docs.libuv.org/en/v1.x/guide/utilities.html#external-i-o-with-polling</issue_description>

<agent_instructions>调研与libuv集成方案,实现高性能请求访问
</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 2 commits March 20, 2026 10:48
Adds MultiUv — a new event-driven alternative to the blocking Multi interface:

- src/MultiUv.zig: Uses curl_multi_socket_action + libuv uv_poll_t/uv_timer_t
  for epoll/kqueue-based I/O notification instead of curl_multi_poll
- src/root.zig: Conditionally exports MultiUv (void when -Dlibuv=false)
- build.zig: Adds -Dlibuv=true/false option, multi-uv example, libuv linking
- examples/multi_uv.zig: Demonstrates three concurrent GETs via uv_run()
- Makefile: Adds run-libuv target

Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate with libuv for better performance Add libuv-backed MultiUv for event-driven concurrent HTTP transfers Mar 20, 2026
Copilot AI requested a review from jiacai2050 March 20, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate with libuv for better perf

2 participants