pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: ivanstepanovftw (@ivanstepanovftw) <noreply+ivanstepanovftw@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #709: Shouldn't there be `restrict` keyword at parameters in `VectorInnerProduct()`?
Date: Sat, 09 Nov 2024 15:40:42 +0000
Message-ID: <gh-pgvector-pgvector-709-c2466261713@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-709@github.com>
References: <gh-pgvector-pgvector-709@github.com>

Hi!

Fortunately, it allows for additional optimizations, that's why this keyword exist.

But I am not sure if it will help. I am lazy and installed pgvector on Ubuntu from APT, and I measured just 2 instructions per CPU cycle per 1 worker process while SELECTing all cosine distances without LIMIT or distance FILTER:
```console
$ sudo perf stat -p 182592 -e instructions,cycles sleep 10

 Performance counter stats for process id '182592':

    57,805,424,818      instructions                     #    2.09  insn per cycle
    27,594,222,817      cycles

      10.002322909 seconds time elapsed
```

I am probably need to build and install pgvector from sources to enable optimizations for my CPU, measure performance, build with `restrict` and measure again.

Current code in `VectorInnerProduct` is not optimal, and in my tests matrix multiplication in Zig performed twice faster, but we are dealing with C and dot product... In my code I've tried to put `restrict` in my C code matrix multiplication without luck. The issue with my C naive matrix multiplication was a lots of branch misses compared to Zig implementation. Maybe bottleneck with this `VectorInnerProduct` function is not even CPU but cache locality, or memory bandwidth.

view thread (11+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-709-c2466261713@github.com>
Permalink:  ../gh-pgvector-pgvector-709-c2466261713@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