Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 13 additions & 9 deletions src/client/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ import { SessionDataSet } from "./SessionDataSet";
import { RowRecord } from "./RowRecord";
import { BaseColumnDecoder, ColumnEncoding, Column } from "./ColumnDecoder";
import { RedirectException } from "../utils/Errors";
import {
serializeColumnFast,
serializeTimestamps
import {
serializeTabletValuesFast,
serializeTimestamps
} from "../utils/FastSerializer";
import { globalBufferPool } from "../utils/BufferPool";
import { parseDateToInt, parseIntToDate } from "../utils/DataTypes";

const ttypes = require("../thrift/generated/client_types");
Expand Down Expand Up @@ -611,7 +610,15 @@ export class Session {
dataTypes: number[],
rowCount: number,
): Buffer {
// Serialize tablet values based on data types
// Fast path (default): single-pass, single-buffer serialization of all
// columns + null bitmaps — no transpose, no per-column intermediate
// buffers, no trailing Buffer.concat. Wire format is identical to the
// legacy path below.
if (this.config.enableFastSerialization) {
return serializeTabletValuesFast(values, dataTypes, rowCount);
}

// Legacy path: per-column serialization + Buffer.concat
// Format: all columns data, then bitmap for null values
const buffers: Buffer[] = [];
const bitMaps: (boolean[] | null)[] = [];
Expand All @@ -635,10 +642,7 @@ export class Session {
}
}

// Use fast serialization if enabled, otherwise fall back to legacy
const buffer = this.config.enableFastSerialization
? serializeColumnFast(columnValues, dataType)
: this.serializeColumn(columnValues, dataType);
const buffer = this.serializeColumn(columnValues, dataType);
buffers.push(buffer);
bitMaps.push(hasNull ? nullBitmap : null);
}
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export { RedirectException, TSStatusCode } from "./utils/Errors";
export { RedirectCache } from "./client/RedirectCache";
export { enableGlobalCleanup } from "./utils/ProcessCleanup";
export { BufferPool, globalBufferPool } from "./utils/BufferPool";
export { serializeColumnFast, serializeTimestamps } from "./utils/FastSerializer";
export {
serializeColumnFast,
serializeTimestamps,
serializeTabletValuesFast,
} from "./utils/FastSerializer";

// Concurrent execution utilities for Node.js optimization
export {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/BufferPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import { logger } from "./Logger";
/**
* Buffer pool for reusing buffers to reduce GC pressure
* Inspired by pg nodejs client's buffer management strategy
*
*
* @deprecated No longer used internally. The write path never called
* release(), so the pool had a 0% hit rate and acquire() was pure overhead
* over Buffer.allocUnsafe. Kept only because it is part of the public API
* surface (exported from src/index.ts); may be removed in a future major
* version.
*
* Key design principles:
* 1. Size classes to minimize waste (powers of 2)
* 2. Maximum pool size to prevent memory bloat
Expand Down
7 changes: 4 additions & 3 deletions src/utils/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ export interface Config {
enableSSL?: boolean;
sslOptions?: SSLOptions;
/**
* Enable optimized fast serialization with buffer pooling.
* Improves performance by 2-3x but may increase memory usage slightly.
* Inspired by pg nodejs client's buffer management.
* Enable the optimized tablet serialization path: single-pass,
* single-buffer writes with inline null bitmaps (no intermediate
* per-column buffers or Buffer.concat), BigInt-free int64 writes.
* Produces byte-identical wire output to the legacy path.
*
* @default true
*/
Expand Down
Loading
Loading