Skip to content

Commit

Permalink
add custom allocator on lantern
Browse files Browse the repository at this point in the history
  • Loading branch information
broccoliSpicy committed Apr 15, 2024
1 parent 4255588 commit 63672d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/hnsw/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_
opts.retriever = ldb_wal_index_node_retriever;
opts.retriever_mut = ldb_wal_index_node_retriever_mut;

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

buildstate->usearch_index = usearch_init(&opts, buildstate->pq_codebook, &error);
elog(INFO, "done init usearch index");
assert(error == NULL);
Expand Down Expand Up @@ -590,6 +594,10 @@ static void BuildEmptyIndex(Relation index, IndexInfo *indexInfo, ldb_HnswBuildS
assert(0 < opts.num_centroids && opts.num_centroids <= 256);
}

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

buildstate->usearch_index = usearch_init(&opts, buildstate->pq_codebook, &error);
assert(error == NULL);

Expand Down
5 changes: 5 additions & 0 deletions src/hnsw/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ bool ldb_aminsert(Relation index,
assert(tmp_num_centroids == hdr->num_centroids);
assert(tmp_num_subvectors == hdr->num_subvectors);
}

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

// todo:: do usearch init in indexInfo->ii_AmCache
uidx = usearch_init(&opts, insertstate->pq_codebook, &error);
if(uidx == NULL) {
Expand Down
4 changes: 4 additions & 0 deletions src/hnsw/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ IndexScanDesc ldb_ambeginscan(Relation index, int nkeys, int norderbys)
opts.expansion_add,
opts.expansion_search);

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

scanstate->usearch_index = usearch_init(&opts, scanstate->pq_codebook, &error);
if(error != NULL) elog(ERROR, "error loading index: %s", error);
assert(error == NULL);
Expand Down

0 comments on commit 63672d9

Please sign in to comment.