[ 
https://issues.apache.org/jira/browse/BEAM-10549?focusedWorklogId=467110&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-467110
 ]

ASF GitHub Bot logged work on BEAM-10549:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Aug/20 07:13
            Start Date: 06/Aug/20 07:13
    Worklog Time Spent: 10m 
      Work Description: saavannanavati commented on a change in pull request 
#12352:
URL: https://github.com/apache/beam/pull/12352#discussion_r466192829



##########
File path: sdks/python/apache_beam/typehints/typecheck.py
##########
@@ -265,3 +268,71 @@ def visit_transform(self, applied_transform):
                 transform.get_type_hints(),
                 applied_transform.full_label),
             applied_transform.full_label)
+
+
+class PerformanceTypeCheckVisitor(pipeline.PipelineVisitor):
+
+  _in_combine = False
+  combine_classes = (
+      core.CombineFn,
+      core.CombinePerKey,
+      core.CombineValuesDoFn,
+      core.CombineValues,
+      core.CombineGlobally)
+
+  def enter_composite_transform(self, applied_transform):
+    if isinstance(applied_transform.transform, self.combine_classes):
+      self._in_combine = True
+
+  def leave_composite_transform(self, applied_transform):
+    if isinstance(applied_transform.transform, self.combine_classes):
+      self._in_combine = False
+
+  def visit_transform(self, applied_transform):
+    transform = applied_transform.transform
+    if isinstance(transform, core.ParDo):
+      if not self._in_combine:
+        transform.fn._full_label = applied_transform.full_label
+        self.store_type_hints(transform)
+
+  def store_type_hints(self, transform):
+    type_hints = transform.get_type_hints()
+
+    input_types = None
+    if type_hints.input_types:
+      normal_hints, kwarg_hints = type_hints.input_types
+
+      if kwarg_hints:
+        input_types = kwarg_hints
+      if normal_hints:
+        input_types = normal_hints
+
+    output_types = None
+    if type_hints.output_types:
+      normal_hints, kwarg_hints = type_hints.output_types
+
+      if kwarg_hints:
+        output_types = kwarg_hints
+      if normal_hints:
+        output_types = normal_hints
+
+    try:
+      argspec = inspect.getfullargspec(transform.fn._process_argspec_fn())
+      if len(argspec.args):
+        arg_index = 0
+        if argspec.args[0] == 'self':
+          arg_index = 1
+        transform.fn._runtime_parameter_name = argspec.args[arg_index]
+        if isinstance(input_types, dict):
+          input_types = (input_types[argspec.args[arg_index]], )
+    except TypeError:
+      pass
+
+    if input_types and len(input_types):
+      input_types = input_types[0]
+
+    if output_types and len(output_types):
+      output_types = output_types[0]
+
+    transform.fn._runtime_type_hints = type_hints._replace(
+        input_types=input_types, output_types=output_types)

Review comment:
       - Through debugging, I've noticed that the type hints are always stored 
in the transforms and not the DoFn's for some reason. Do you know of a case 
where the DoFn stores the type hint?
   
   - Sounds good, moved (most of) the pre-processing computation here




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 467110)
    Time Spent: 2h 40m  (was: 2.5h)

> Improve Runtime Type Checking Performance
> -----------------------------------------
>
>                 Key: BEAM-10549
>                 URL: https://issues.apache.org/jira/browse/BEAM-10549
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-py-core
>            Reporter: Saavan Nanavati
>            Assignee: Saavan Nanavati
>            Priority: P2
>          Time Spent: 2h 40m
>  Remaining Estimate: 0h
>
> The performance gain will come from moving the runtime type check from a 
> decorator to OperationCounters.
>  
> This has (2) improvements:
>  # Cython optimizable
>  # Sampling is a built-in feature
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to