You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5280149
Browse filesBrowse the repository at this point in the historyBrowse files
Make persistent connections actually reuse the socket
Re-running the benchmark after the timeout change showed persistent and
non-persistent within noise of each other, and the connection pool
always empty. Root cause is in std.http.Client.fetch (0.16): when a body
is both compressed and chunked, which is serpapi.com's default framing,
the decompressor stops at the end of the gzip stream and the terminating
"0\r\n\r\n" chunk is never read. Request.deinit then sees the body as
unfinished and closes the connection, so keep_alive was silently a no-op
and every request paid for a fresh TCP + TLS handshake.
fetchStatus now drives the request itself (mirroring fetch) and, after
the decompressed body has been streamed, drains the remaining framing
through req.reader.interface so the body is marked complete and the
connection returns to the pool.
zig build bench, 10 sequential searches, three rounds:
before: non-persistent 2.1-2.5s, persistent 2.4-2.7s
after: non-persistent 2.1-2.4s, persistent 0.5-1.0s (3-4x)
A unit test serves two chunked gzip responses on one loopback connection
and asserts the pool holds the connection between them; it fails without
the drain. Docs updated from the old "2x" claim, which the code had never
actually delivered.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: README.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ SerpApi supports Google, Google Maps, Google Shopping, Baidu, Yandex, Yahoo, eBa
13
13
Query a vast range of data at scale, including web search results, flight schedules, stock market data, news headlines, and [more](https://serpapi.com).
14
14
15
15
## Features
16
-
*`persistent` → Keep socket connection open to save on SSL handshake / reconnection (2x faster).
16
+
*`persistent` → Keep socket connection open to save on SSL handshake / reconnection (3-4x faster on repeated searches).
17
17
*`md` → Markdown output, token-efficient and ready to feed to LLMs and AI agents. [Search API — Markdown](#search-api--markdown)
18
18
* zero dependency → only the Zig standard library (`std.http`, `std.json`), nothing else to fetch.
19
19
* cross platform → Linux, macOS, and Windows.
@@ -317,8 +317,10 @@ var results = try client.searchArchive(search_id);
317
317
## Search at scale
318
318
319
319
With `persistent = true` (the default), the client keeps the TLS connection
320
-
to serpapi.com open between requests, which roughly doubles throughput on
321
-
repeated searches (measure it yourself with `zig build bench`):
320
+
to serpapi.com open between requests, skipping the TCP + TLS handshake on
321
+
every search after the first. On repeated searches this is 3-4x faster than
322
+
reconnecting (10 sequential searches: ~0.5-1.0s persistent vs ~2.2s not;
0 commit comments