rohdesamuel commented on code in PR #25354:
URL: https://github.com/apache/beam/pull/25354#discussion_r1114770702


##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/debug/OutputSampler.java:
##########
@@ -104,19 +104,22 @@ public List<BeamFnApi.SampledElement> samples() throws 
IOException {
 
     // Serializing can take a lot of CPU time for larger or complex elements. 
Copy the array here
     // so as to not slow down the main processing hot path.
-    List<T> copiedBuffer;
+    List<T> bufferToSend;
+    int sampleIndex = 0;
     synchronized (this) {
-      copiedBuffer = new ArrayList<>(buffer);
-      buffer.clear();
+      bufferToSend = buffer;
+      sampleIndex = resampleIndex;
+      buffer = new ArrayList<>(maxElements);
       resampleIndex = 0;
     }
 
     ByteStringOutputStream stream = new ByteStringOutputStream();
-    for (T el : copiedBuffer) {
+    for (int i = 0; i < bufferToSend.size(); i++) {
+      int index = (sampleIndex + i) % bufferToSend.size();

Review Comment:
   True, but this did make testing it easier. Without this, the elements are 
read out of order because old samples are overwritten in the array.



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

Reply via email to