Skip to content

TypeScript SDK: Avoid options-bag allocation on feedback fast path #33

Description

@coreyt

Context

Every SDK method that supports progress callbacks constructs a runWithFeedback options object on every call, even when no callback is provided:

write(request, progressCallback?, feedbackConfig?) {
  return this.#run("write.submit", () => ..., progressCallback, feedbackConfig);
}
// #run builds: { operationKind, metadata: {}, progressCallback, feedbackConfig, operation }

The runWithFeedback function has an early return when progressCallback is undefined, but the call-site allocation (options bag + metadata: {} literal) still occurs.

Impact

Low — the allocation is a single small object per call and V8 is very efficient at short-lived allocations. Only matters for extremely high-frequency operations (thousands of writes/queries per second).

Proposed Fix

Check progressCallback before calling runWithFeedback at all:

#run<T>(operationKind: string, operation: () => T, pc?: ProgressCallback, fc?: FeedbackConfig): T {
  if (!pc) return operation();
  return runWithFeedback({ operationKind, metadata: {}, progressCallback: pc, feedbackConfig: fc, operation });
}

This eliminates the options-bag allocation entirely on the fast path.

Files

  • typescript/packages/fathomdb/src/engine.ts (#run)
  • typescript/packages/fathomdb/src/query.ts (#run)
  • typescript/packages/fathomdb/src/admin.ts (#run)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions