mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-03 03:00:56 +08:00
Added benchmarking for HNSW vacuuming [skip ci]
This commit is contained in:
@@ -1329,7 +1329,7 @@ make clean && PG_CFLAGS="-DUSE_ASSERT_CHECKING" make && make install
|
||||
To enable benchmarking:
|
||||
|
||||
```sh
|
||||
make clean && PG_CFLAGS="-DIVFFLAT_BENCH" make && make install
|
||||
make clean && PG_CFLAGS="-DHNSW_BENCH -DIVFFLAT_BENCH" make && make install
|
||||
```
|
||||
|
||||
To show memory usage:
|
||||
|
||||
19
src/hnsw.h
19
src/hnsw.h
@@ -18,6 +18,10 @@
|
||||
#include "utils/sampling.h"
|
||||
#include "vector.h"
|
||||
|
||||
#ifdef HNSW_BENCH
|
||||
#include "portability/instr_time.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 190000
|
||||
typedef Pointer Item;
|
||||
#endif
|
||||
@@ -78,6 +82,21 @@ typedef Pointer Item;
|
||||
#define HnswPageGetOpaque(page) ((HnswPageOpaque) PageGetSpecialPointer(page))
|
||||
#define HnswPageGetMeta(page) ((HnswMetaPageData *) PageGetContents(page))
|
||||
|
||||
#ifdef HNSW_BENCH
|
||||
#define HnswBench(name, code) \
|
||||
do { \
|
||||
instr_time start; \
|
||||
instr_time duration; \
|
||||
INSTR_TIME_SET_CURRENT(start); \
|
||||
(code); \
|
||||
INSTR_TIME_SET_CURRENT(duration); \
|
||||
INSTR_TIME_SUBTRACT(duration, start); \
|
||||
elog(INFO, "%s: %.3f ms", name, INSTR_TIME_GET_MILLISEC(duration)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define HnswBench(name, code) (code)
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 150000
|
||||
#define RandomDouble() pg_prng_double(&pg_global_prng_state)
|
||||
#define SeedRandom(seed) pg_prng_seed(&pg_global_prng_state, seed)
|
||||
|
||||
@@ -669,13 +669,13 @@ hnswbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
|
||||
InitVacuumState(&vacuumstate, info, stats, callback, callback_state);
|
||||
|
||||
/* Pass 1: Remove heap TIDs */
|
||||
RemoveHeapTids(&vacuumstate);
|
||||
HnswBench("RemoveHeapTids", RemoveHeapTids(&vacuumstate));
|
||||
|
||||
/* Pass 2: Repair graph */
|
||||
RepairGraph(&vacuumstate);
|
||||
HnswBench("RepairGraph", RepairGraph(&vacuumstate));
|
||||
|
||||
/* Pass 3: Mark as deleted */
|
||||
MarkDeleted(&vacuumstate);
|
||||
HnswBench("MarkDeleted", MarkDeleted(&vacuumstate));
|
||||
|
||||
FreeVacuumState(&vacuumstate);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user