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

perf(NODE-6356): Improve serialization performance #709

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/bson_value.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { BSON_MAJOR_VERSION } from './constants';
import { type InspectFn } from './parser/utils';
import { BSON_VERSION_SYMBOL } from './constants';

/** @public */
export abstract class BSONValue {
/** @public */
public abstract get _bsontype(): string;

/** @internal */
get [Symbol.for('@@mdb.bson.version')](): typeof BSON_MAJOR_VERSION {
get [BSON_VERSION_SYMBOL](): typeof BSON_MAJOR_VERSION {
return BSON_MAJOR_VERSION;
}

Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @internal */
export const BSON_MAJOR_VERSION = 6;

/** @internal */
export const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');

/** @internal */
export const BSON_INT32_MAX = 0x7fffffff;
/** @internal */
Expand Down
5 changes: 3 additions & 2 deletions src/extended_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
BSON_INT32_MIN,
BSON_INT64_MAX,
BSON_INT64_MIN,
BSON_MAJOR_VERSION
BSON_MAJOR_VERSION,
BSON_VERSION_SYMBOL
} from './constants';
import { DBRef, isDBRefLike } from './db_ref';
import { Decimal128 } from './decimal128';
Expand Down Expand Up @@ -358,7 +359,7 @@ function serializeDocument(doc: any, options: EJSONSerializeOptions) {
doc != null &&
typeof doc === 'object' &&
typeof doc._bsontype === 'string' &&
doc[Symbol.for('@@mdb.bson.version')] !== BSON_MAJOR_VERSION
doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION
) {
throw new BSONVersionError();
} else if (isBSONType(doc)) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/calculate_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function calculateElement(
if (
value != null &&
typeof value._bsontype === 'string' &&
value[Symbol.for('@@mdb.bson.version')] !== constants.BSON_MAJOR_VERSION
value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION
) {
throw new BSONVersionError();
} else if (value == null || value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
Expand Down
Loading