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!



-- 
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.

To unsubscribe, e-mail: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to