-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-16524][python] Optimize the execution of Python UDF to use generator to eliminate unnecessary function calls #11374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit 9cb59ec (Wed Mar 11 08:01:22 UTC 2020) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. DetailsThe Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
9cb59ec to
359627a
Compare
…wCoder to generator to eliminate unnecessary function calls
359627a to
ef45405
Compare
| data_out_stream = self.data_out_stream | ||
| for value in iter_value: | ||
| self.write_null_mask(value, data_out_stream) | ||
| for i in range(self._filed_count): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename _filed_count to _field_count? It's not directly related to this PR, however it would be great if we can correct the typo as it's used in this PR.
| while in_stream.size() > 0: | ||
| yield self.create_result(in_stream, nested) | ||
|
|
||
| def create_result(self, in_stream: create_InputStream, nested: bool) -> List: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to _decode_one_row_from_stream?
| arrays = [create_array(cols[i], self._schema.types[i]) for i in range(0, len(self._schema))] | ||
| return pa.RecordBatch.from_arrays(arrays, self._schema) | ||
|
|
||
| def _create_result(self, in_stream: create_InputStream) -> List: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to _decode_one_row_from_stream
|
|
||
| def _create_result(self, in_stream: create_InputStream) -> List: | ||
| self._resettable_io.set_input_bytes(in_stream.read_all(True)) | ||
| # there is only arrow batch in the underlying input stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help to correct the comments here?
there is only arrow batch -> there is only one arrow batch
| self._value_coder.encode_to_stream(value, out, nested) | ||
|
|
||
| def decode_from_stream(self, in_stream: create_InputStream, nested: bool) -> Any: | ||
| return self._value_coder.decode_from_stream(in_stream, False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decode_from_stream(in_stream, False) -> decode_from_stream(in_stream, nested) ?
| return 'ArrowCoder[%s]' % self._schema | ||
|
|
||
|
|
||
| class CustomLengthPrefixCoder(LengthPrefixCoder): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about rename it to PassThroughLengthPrefixCoder to reflect that it does nothing for the prefixed length?
|
|
||
| class CustomLengthPrefixCoder(LengthPrefixCoder): | ||
| """ | ||
| CustomLengthPrefixCoder will replace LengthPrefixCoder in Beam for performance optimization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the comment as following?
Coder which doesn't prefix the length of the encoded object as the length prefix will be handled by the wrapped value coder.
…wCoder to generator to eliminate unnecessary function calls-fix-1
|
Thanks a lot for @dianfu review, I have addressed the comments at the latest commit. |
…wCoder to generator to eliminate unnecessary function calls-fix-2
dianfu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HuangXingBo Thanks for the update. LGTM.
…tor to eliminate unnecessary function calls (apache#11374)
What is the purpose of the change
This pull request will optimize the result of FlattenRowCoder and ArrowCoder to generator to eliminate unnecessary function calls
Brief change log
Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
@Public(Evolving): (no)Documentation
How does this patch test
Test Code
Test Results
num rows, num colums | Consume Time(Before) | Consume Time(After)
10kw,1 | 711s | 441s
10kw,10 | 1454s | 1221s