[WIP][SPARK-?????][STREAMING] Make small optimizations to StatefulProcessorApiClient#56786
Draft
funrollloops wants to merge 3 commits into
Draft
[WIP][SPARK-?????][STREAMING] Make small optimizations to StatefulProcessorApiClient#56786funrollloops wants to merge 3 commits into
funrollloops wants to merge 3 commits into
Conversation
HyukjinKwon
reviewed
Jun 25, 2026
HyukjinKwon
left a comment
Member
There was a problem hiding this comment.
2 blocking, 0 non-blocking, 1 nit.
The closure-hoisting optimization is good; the serializer swap and the fast-path subclass leak read as unintended behavior changes for a "small optimizations" PR.
Correctness (2)
- stateful_processor_api_client.py:110:
PickleSerializer()drops cloudpickle —CPickleSerializerdefaults toCloudPickleSerializer— see inline - stateful_processor_api_client.py:45: scalar fast-path returns
np.float64/pd.Timestampunconverted (they subclassfloat/datetime) — see inline
Nits: 1 minor item (see inline comments).
Verification
Confirmed empirically: issubclass(np.float64, float) and issubclass(pandas.Timestamp, datetime) are both True, while np.int64/np.bool_ are not subclasses of int/bool. So the new fast-path leaks exactly np.float64 and pd.Timestamp (returned as-is, skipping .tolist()/.to_pydatetime()), while np.int64/np.bool_ still correctly reach the np.generic branch.
PR description suggestions
- Document: why the serializer is changed from
CPickleSerializertoPickleSerializer(this is a capability change, not just an optimization) — and whether dropping cloudpickle is intended. - Add: a real JIRA id (currently
SPARK-?????) and a short note on what is being optimized and how it was measured.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Make two small optimizations to StatefulProcessorApiClient:
mapto generator comprehensions, and move the numpy import and function definition to the top level so it is done onceWhy are the changes needed?
Together these changes improve transform with state on a simple rolling-window style benchmark by ~10%.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing unit tests.
Was this patch authored or co-authored using generative AI tooling?
No, but Claude was consulted in the process of producing this PR.