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

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

                Author: ASF GitHub Bot
            Created on: 22/Mar/22 16:24
            Start Date: 22/Mar/22 16:24
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on a change in pull request #17134:
URL: https://github.com/apache/beam/pull/17134#discussion_r832369579



##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/coders/BitConverters.java
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.coders;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.primitives.Longs;
+
+class BitConverters {
+  private BitConverters() {}
+
+  private static void readFully(InputStream in, byte[] b) throws IOException {
+    int len = b.length;
+    int n = 0;
+    while (n < len) {
+      int count = in.read(b, n, len - n);
+      if (count < 0) {
+        throw new EOFException();
+      }
+      n += count;
+    }
+  }

Review comment:
       ```suggestion
   
   import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.io.ByteStreams.readFully;
   
   import java.io.EOFException;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
   import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.primitives.Longs;
   
   /** Convert between Java value types and specific encodings of those value 
types. */
   class BitConverters {
     private BitConverters() {}
   ```




-- 
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: [email protected]

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


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

    Worklog Id:     (was: 745908)
    Time Spent: 3.5h  (was: 3h 20m)

> Many coders cause significant unnecessary allocations
> -----------------------------------------------------
>
>                 Key: BEAM-14134
>                 URL: https://issues.apache.org/jira/browse/BEAM-14134
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-core
>            Reporter: Steve Niemitz
>            Assignee: Steve Niemitz
>            Priority: P2
>          Time Spent: 3.5h
>  Remaining Estimate: 0h
>
> Many coders (BigEndian*, Map, Iterable, Instant) use DataInputStream to read 
> longs/ints/shorts.  Internally each DataInputStream allocates ~200 bytes of 
> buffers when instantiated.  This means every long, int, short, etc decoded 
> allocates over 200 bytes.
> We should eliminate all uses of DataInputStream in hot-paths and replace it 
> with something more efficient.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to