python icon indicating copy to clipboard operation
python copied to clipboard

feat: Add option to control deserialization when watching events

Open Kevinz857 opened this issue 7 months ago • 3 comments

What type of PR is this?

/kind feature /kind optimization

What this PR does / why we need it

This PR adds an option to disable automatic deserialization in the Watch.stream() method. When watching large volumes of resource updates, the default deserialization of every event can cause significant latency overhead and potential processing delays.

By allowing clients to opt-out of automatic deserialization when only basic JSON parsing is needed, we can significantly reduce time cost and improve event processing throughput. This is particularly important in scenarios with high event volumes or resource constraints, where the overhead of deserializing every object into full model instances becomes a bottleneck.

Key changes

  • Added a deserialize parameter to Watch.stream() method (defaults to True for backward compatibility)
  • When deserialize=False, events are only JSON parsed without model conversion
  • Maintains the original behavior when deserialize=True
  • Added test cases to verify both behaviors

Special notes for your reviewer

This change is backward compatible with existing code as it defaults to the current behavior (deserialize=True). Users can specifically opt-in to the performance optimization by setting deserialize=False when needed.

Does this PR introduce a user-facing change?

Add option to disable automatic deserialization in the Watch.stream() method to improve performance in high-volume watching scenarios

Kevinz857 avatar May 31 '25 10:05 Kevinz857

@Kevinz857: The label(s) kind/optimization cannot be applied, because the repository doesn't have them.

In response to this:

What type of PR is this?

/kind feature /kind optimization

What this PR does / why we need it

This PR adds an option to disable automatic deserialization in the Watch.stream() method. When watching large volumes of resource updates, the default deserialization of every event can cause significant latency overhead and potential processing delays.

By allowing clients to opt-out of automatic deserialization when only basic JSON parsing is needed, we can significantly reduce time cost and improve event processing throughput. This is particularly important in scenarios with high event volumes or resource constraints, where the overhead of deserializing every object into full model instances becomes a bottleneck.

Key changes

  • Added a deserialize parameter to Watch.stream() method (defaults to True for backward compatibility)
  • When deserialize=False, events are only JSON parsed without model conversion
  • Maintains the original behavior when deserialize=True
  • Added test cases to verify both behaviors

Special notes for your reviewer

This change is backward compatible with existing code as it defaults to the current behavior (deserialize=True). Users can specifically opt-in to the performance optimization by setting deserialize=False when needed.

Does this PR introduce a user-facing change?

Add option to disable automatic deserialization in the Watch.stream() method to improve performance in high-volume watching scenarios

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar May 31 '25 10:05 k8s-ci-robot

/assign

roycaihw avatar Jun 04 '25 20:06 roycaihw

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Kevinz857, roycaihw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Jun 24 '25 20:06 k8s-ci-robot