Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: perf issue, do not load proto on each search() call #124

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions milvus/Data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import protobuf from 'protobufjs';
import protobuf, { Root } from 'protobufjs';
import { promisify } from '../utils';
import { Client } from './Client';
import { Collection } from './Collection';
Expand Down Expand Up @@ -49,10 +49,14 @@ export class Data extends Client {
vectorTypes: number[];
collectionManager: Collection;

private readonly _protoRoot: Root;

constructor(client: any, collectionManager: Collection) {
super(client);
this.vectorTypes = [DataType.BinaryVector, DataType.FloatVector];
this.collectionManager = collectionManager;

this._protoRoot = protobuf.loadSync(protoPath)
}

/**
Expand Down Expand Up @@ -302,7 +306,6 @@ export class Data extends Client {
* ```
*/
async search(data: SearchReq): Promise<SearchResults> {
const root = await protobuf.load(protoPath);
this.checkCollectionName(data);
if (
!data.search_params ||
Expand Down Expand Up @@ -348,7 +351,7 @@ export class Data extends Client {
}

// when data type is bytes , we need use protobufjs to transform data to buffer bytes.
const PlaceholderGroup = root.lookupType(
const PlaceholderGroup = this._protoRoot.lookupType(
'milvus.proto.common.PlaceholderGroup'
);
// tag $0 is hard code in milvus, when dsltype is expr
Expand Down