[
https://issues.apache.org/jira/browse/BEAM-14347?focusedWorklogId=765622&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-765622
]
ASF GitHub Bot logged work on BEAM-14347:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 03/May/22 18:32
Start Date: 03/May/22 18:32
Worklog Time Spent: 10m
Work Description: damccorm commented on code in PR #17429:
URL: https://github.com/apache/beam/pull/17429#discussion_r864075000
##########
sdks/go/pkg/beam/registration/registration.tmpl:
##########
@@ -0,0 +1,252 @@
+{{define "BuildWrapper_StartFinishBundle"}}
+{{$lowerName := "unknown"}}{{$upperName := "unknown"}}{{if (eq .func
"startBundle")}}{{$lowerName = "startBundle"}}{{$upperName =
"StartBundle"}}{{end}}{{if (eq .func "finishBundle")}}{{$lowerName =
"finishBundle"}}{{$upperName = "FinishBundle"}}{{end}}{{$startFinishBundleMaxIn
:= .startFinishBundleMaxIn}}{{$processElementMaxIn := .processElementMaxIn}}
+{{range $numParams := upto $processElementMaxIn}}
+func build{{$upperName}}Wrapper{{$numParams}}{{(genericTypingRepresentation
$numParams 0 true)}}(doFn interface{}) func(interface{}) reflectx.Func {
+ {{$lowerName}}In := -1
+ {{$lowerName}}Out := -1
+ {{$lowerName}}Method :=
reflect.ValueOf(doFn).MethodByName("{{$upperName}}")
+ if {{$lowerName}}Method.IsValid() {
+ {{$lowerName}}In = {{$lowerName}}Method.Type().NumIn()
+ {{$lowerName}}Out = {{$lowerName}}Method.Type().NumOut()
+ switch {
+{{range $funcIn := upto $startFinishBundleMaxIn}}
+ case {{$lowerName}}In == {{$funcIn}}:
+ switch { {{range $funcOut := upto 2}}{{$possibleCombos :=
(possibleBundleLifecycleParameterCombos $funcIn $numParams)}}{{if
$possibleCombos}}
+ case {{$lowerName}}Out == {{$funcOut}}:
+{{$first := true}}{{range $funcCombo := $possibleCombos}}{{if $first}}{{$first
= false}} {{else}} else {{end}}if _, ok :=
doFn.({{$lowerName}}{{$funcIn}}x{{$funcOut}}{{if (or $funcIn
$funcOut)}}[{{(join $funcCombo ", ")}}{{if $funcOut}}{{if $funcIn}},
{{end}}error{{end}}]{{end}}); ok {
+ reflectx.RegisterFunc(reflect.TypeOf((*func({{(join
$funcCombo ", ")}}){{if $funcOut}} error{{end}})(nil)).Elem(), func(fn
interface{}) reflectx.Func { return &caller{{$funcIn}}x{{$funcOut}}{{if (or
$funcIn $funcOut)}}[{{(join $funcCombo ", ")}}{{if $funcOut}}{{if $funcIn}},
{{end}}error{{end}}]{{end}}{fn: fn.(func({{(join $funcCombo ", ")}}){{if
$funcOut}} error{{end}})} })
+ {{$funcRegister := (makeStructRegisterEntry $lowerName
$upperName $funcCombo (list))}}{{if $funcOut}}{{$funcRegister =
(makeStructRegisterEntry $lowerName $upperName $funcCombo (list
"error"))}}{{end}}
+ return func(fn interface{}) reflectx.Func { return
{{$funcRegister}} }
Review Comment:
This did help significantly, even after the previous optimization - done!
Issue Time Tracking
-------------------
Worklog Id: (was: 765622)
Time Spent: 4h 10m (was: 4h)
> [Go SDK] Allow users to optimize DoFns with a single generic registration
> function
> ----------------------------------------------------------------------------------
>
> Key: BEAM-14347
> URL: https://issues.apache.org/jira/browse/BEAM-14347
> Project: Beam
> Issue Type: New Feature
> Components: sdk-go
> Reporter: Danny McCormick
> Assignee: Danny McCormick
> Priority: P2
> Time Spent: 4h 10m
> Remaining Estimate: 0h
>
> Right now, to optimize DoFn execution, users have to use the code generator.
> This updates to allow them to use generics instead.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)