pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: Manuelreyesbravo (@Manuelreyesbravo) <noreply+Manuelreyesbravo@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] PR #1020: Prefetch unvisited neighbors during HNSW search
Date: Sun, 27 Sep 2026 03:00:50 +0000
Message-ID: <gh-pgvector-pgvector-1020-c5852142635@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-1020@github.com>
References: <gh-pgvector-pgvector-1020@github.com>

Thanks, you're right that the limit matters, and it changes the picture. I added it the way the hnsw-prefetch comment suggests: at most `get_tablespace_io_concurrency()` prefetches outstanding per hop (the first eic up front, then one more for each neighbor read).

Same setup as before (500k x 1536, io_uring), a new run pinned to one CCX, so the numbers differ slightly from my previous table; local NVMe / +1 ms per read, median of 10-14 runs:

| | eic 16 | eic 64 |
|---|---|---|
| `FULL` + pause | 1.38 s / 10.2 s | 1.34 s / 7.2 s |
| prefetch, limited by eic | 1.34 s / 10.3 s | 1.19 s / 6.8 s |
| prefetch, not limited (as in this PR) | 1.20 s / 6.8 s | 1.20 s / 6.8 s |

So at the default eic, the PR's advantage came from ignoring effective_io_concurrency; with the limit it is about even with the read stream + pause. At eic 64 the limit makes no difference, as you said.

On the remaining gap at eic 64: the backend uses about twice the system time with the read stream, and that part is io_uring handing reads to its worker threads. `pgaio_uring_should_use_async()` sets `IOSQE_ASYNC` on buffered reads once more than 4 IOs are in flight, and most of the ~28 reads in a hop hit that. In a build where it returns false, the stream's system time at +1 ms drops from 0.81 s to 0.50 s per run (prefetch: 0.41 s). But the time doesn't change (7.11 s in both builds, against 6.78 s for prefetch), so that isn't the cause, and I still can't explain the remaining ~5%.

One thing that does help the read stream: while the current hop's reads are in flight, prefetching the unvisited neighbors of the next two candidates, using only what is left of the eic budget after the hop's own reads. In a separate run at eic 64 and +1 ms (so slightly different numbers from the table), that took `FULL` + pause from 7.43 s to 6.53 s, for 8% more reads, below the eic-limited prefetch without it (6.84 s in that run). It changes nothing at eic 16, where the budget is used up, and nothing on the local NVMe.

Given that the two are about even at the default setting, and the read stream gets AIO and I/O accounting from core, I think the read stream with `read_stream_pause` is the better base, and I'm happy to close this PR if you agree. I can send the look-ahead separately on top of your branch, if it's of interest.


view thread (15+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-1020-c5852142635@github.com>
Permalink:  ../gh-pgvector-pgvector-1020-c5852142635@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox