Skip to content

feat(grpc): add response size calculation option - #196

Open
jigetus wants to merge 1 commit into
mainfrom
feat/grpc-response-size-option
Open

feat(grpc): add response size calculation option#196
jigetus wants to merge 1 commit into
mainfrom
feat/grpc-response-size-option

Conversation

@jigetus

@jigetus jigetus commented Sep 5, 2026

Copy link
Copy Markdown
Member

Successful unary gRPC calls currently run object-sizeof before resolving the response, even when an application does not use the size statistic. For large decoded responses, this adds an expensive synchronous JSON serialization pass.

Add the optional calculateResponseSize action setting:

getExport: {
    protoPath: 'exports/v1/export_service.proto',
    protoKey: 'exports.v1.ExportService',
    action: 'GetExport',
    calculateResponseSize: false,
}

The default remains true. Setting it to false skips sizeof and reports responseSize: 0 (not calculated), preserving the existing numeric Stats contract. Other statistics, response data and headers are unchanged. The setting applies to successful unary actions using either proto files or reflection; error statistics and streaming calls retain their existing behavior.

Includes documentation and integration coverage for the omitted, true and false cases. The tests wrap the real object-sizeof implementation and verify that the disabled case makes no call to it.

Validation on Node 20.20.2: lint/build/package exports, typecheck, 48 unit tests, and 27 integration tests passed. patch-package was supplied through a temporary npm exec environment for the integration runner; package dependencies and the lockfile are unchanged.

Summary by Sourcery

Add configurable response-size calculation for successful unary gRPC responses to avoid unnecessary processing when size statistics are not needed.

New Features:

  • Add an optional calculateResponseSize setting for successful unary gRPC actions, defaulting to enabled and supporting both proto-based and reflection-based actions.

Enhancements:

  • Allow applications to skip expensive response-size calculation while preserving sendStats and reporting responseSize: 0 when disabled.
  • Document the response-size calculation option and its behavior.

Documentation:

  • Document configuration and behavior for disabling gRPC response-size calculation.

Tests:

  • Add integration coverage for omitted, enabled, and disabled response-size calculation, including verification that object-sizeof is not called when disabled.

@sourcery-ai

sourcery-ai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an opt-out calculateResponseSize action setting for successful unary gRPC calls, conditionally bypassing the expensive object-sizeof calculation while retaining the numeric stats contract and default behavior, with integration tests and documentation.

File-Level Changes

Change Details Files
Adds an optional per-action switch for calculating successful unary gRPC response sizes while preserving the existing default behavior.
  • Introduces optional calculateResponseSize configuration with a default-enabled contract.
  • Skips object-sizeof and reports responseSize: 0 when explicitly disabled.
  • Limits the behavior change to successful unary actions; streaming and error statistics remain unchanged.
lib/components/grpc.ts
lib/models/common.ts
Adds integration coverage proving default, explicit-enabled, and disabled response-size behavior.
  • Wraps the real object-sizeof implementation to verify invocation and arguments.
  • Asserts response data, stats, and status fields for enabled and disabled calculations.
integration-test/client/unary.test.ts
Documents configuration, semantics, and scope of the response-size option.
  • Adds the option to the README with a usage example.
  • Explains the default, zero-value sentinel, performance motivation, and unsupported streaming/error scope.
README.md

Possibly linked issues

  • #unknown: The PR directly mitigates the reported object-sizeof crash by allowing response size calculation to be disabled.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the option or size calculation is wrong, successful gRPC statistics can be emitted with an incorrect or zero responseSize, and those recorded metrics are not repaired by reverting. The effect is bounded to observability data; reverting restores the prior calculation for future calls.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant