[ 
https://issues.apache.org/jira/browse/BEAM-3388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16338148#comment-16338148
 ] 

ASF GitHub Bot commented on BEAM-3388:
--------------------------------------

aaltay closed pull request #4474: [BEAM-3388] Use a typeswitch instead of 
reflect.Convert
URL: https://github.com/apache/beam/pull/4474
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sdks/go/pkg/beam/core/runtime/exec/coder.go 
b/sdks/go/pkg/beam/core/runtime/exec/coder.go
index f450430c8df..783a08f6456 100644
--- a/sdks/go/pkg/beam/core/runtime/exec/coder.go
+++ b/sdks/go/pkg/beam/core/runtime/exec/coder.go
@@ -134,8 +134,15 @@ type bytesEncoder struct{}
 
 func (*bytesEncoder) Encode(val FullValue, w io.Writer) error {
        // Encoding: size (varint) + raw data
-
-       data := 
reflect.ValueOf(val.Elm).Convert(reflectx.ByteSlice).Interface().([]byte)
+       var data []byte
+       switch v := val.Elm.(type) {
+       case []byte:
+               data = v
+       case string:
+               data = []byte(v)
+       default:
+               return fmt.Errorf("received unknown value type: want []byte or 
string, got %T", v)
+       }
        size := len(data)
 
        if err := coder.EncodeVarInt((int32)(size), w); err != nil {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Reduce Go runtime reflective overhead
> -------------------------------------
>
>                 Key: BEAM-3388
>                 URL: https://issues.apache.org/jira/browse/BEAM-3388
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-go
>            Reporter: Henning Rohde
>            Assignee: Henning Rohde
>            Priority: Major
>             Fix For: 2.3.0
>
>
> Go reflection is slow and we should avoid it in the Go SDK at runtime, when 
> possible -- especially on the fast paths. It seems unlikely that the language 
> runtime/libraries will improve any time soon: 
> https://github.com/golang/go/issues/7818.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to