pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: mikejuliet13 (@mikejuliet13) <noreply+mikejuliet13@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] PR #772: Optimise vector distance functions for IBM Power Architecture
Date: Tue, 29 Apr 2025 12:39:19 +0000
Message-ID: <gh-pgvector-pgvector-772-c2838668710@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-772@github.com>
References: <gh-pgvector-pgvector-772@github.com>

Hi @ankane  ,
Thanks for the follow-up.

My changes leverage Power-specific SIMD intrinsics (Altivec/VSX) along with manual loop unrolling to better utilize the architecture’s capabilities. While the -O3 flag in the original code enables auto-vectorization, it does not perform loop unrolling. This leads to a performance bottleneck—specifically around the xvmaddmsp instruction, which accounts for ~54% of the hotspots in perf, as operations repeatedly funnel through multiply-adds on the same register.

There is clear scope for performance improvement on Power by applying loop unrolling, either manually or via the -funroll-loops compiler flag.

Key Performance Observations (Power10):
Original code + -funroll-loops performs better than without it:
→ QPS improvement: 6–12%
→ Indexing time reduction: 10–20%
(observed primarily on higher-dimensional datasets like fashion-mnist-784-euclidean and gist-960-euclidean)

For lower-dimensional datasets like nytimes-256-angular and glove-100-angular, the performance difference is negligible for both QPS and indexing time.

Optimized code (manual VSX + manual loop unrolling) outperforms even the loop-unrolled original:
→ QPS improvement: 4–10%
→ Indexing time reduction: 10–30%
(notable gains on higher-dimensional datasets and even nytimes-256-angular)

For glove-100-angular, the difference remains minimal.

I tested across the following datasets in both batch and non-batch modes:
fashion-mnist-784-euclidean, gist-960-euclidean, nytimes-256-angular, and glove-100-angular.

Additional Insights:
Higher dimensionality correlates with greater performance benefits from the optimized code.

Larger m and ef_search values also amplify the performance gains in favor of the optimized version.

While auto-vectorization is certainly beneficial, these findings suggest that manual control—particularly with loop unrolling—still delivers tangible performance improvements on Power architecture.

I'm happy to share the full perf data or benchmarking logs if needed.

view thread (13+ messages)  latest in thread

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