lukecwik commented on code in PR #22182:
URL: https://github.com/apache/beam/pull/22182#discussion_r920454143


##########
sdks/java/core/jmh/src/main/java/org/apache/beam/sdk/schemas/RowBundle.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.schemas;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.IntStream.range;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.IntStream;
+import org.apache.beam.sdk.transforms.SerializableFunction;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.RowWithGetters;
+import org.apache.beam.sdk.values.RowWithStorage;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.infra.Blackhole;
+
+/**
+ * Bundle of rows according to the configured {@link Factory} as input for 
benchmarks.
+ *
+ * <p>The rows are created during {@link #setup()} to exclude initialization 
costs from the
+ * measurement. To prevent unintended cache hits in {@link RowWithGetters}, a 
new bundle of rows
+ * must be generated before every invocation.
+ *
+ * <p>Setup per {@link Level#Invocation} has considerable drawbacks. Though, 
given that processing
+ * bundles of rows (n={@link #bundleSize}) takes well above 1 ms, each 
individual invocation can be
+ * adequately timestamped without risking generating wrong results.
+ */
+@State(Scope.Benchmark)
+public class RowBundle {
+  @SuppressWarnings("ImmutableEnumChecker") // false positive
+  public enum Action {
+    /**
+     * Write field to object using {@link
+     * GetterBasedSchemaProvider#fromRowFunction(TypeDescriptor)}.
+     *
+     * <p>Use {@link RowWithStorage} to bypass optimizations in RowWithGetters 
for writes.
+     */
+    WRITE(Factory::createWithStorage),
+
+    /**
+     * Read field from {@link RowWithGetters} provided by {@link
+     * GetterBasedSchemaProvider#toRowFunction(TypeDescriptor)}.
+     */
+    READ_ONCE(Factory::createWithGetter),
+
+    /**
+     * Repeatedly (3x) read field from {@link RowWithGetters} provided by 
{@link

Review Comment:
   My idea was to have coverage to be able to get a field from a row (aka read) 
and set a field on a row (aka write). The use cases I was thinking for a given 
row would be that a user would get the same field from the same row once or 
multiple times and similarly would set a field on the same row once or multiple 
times. As you have done I would repeat this for many rows.
   
   This would highlight the one time cost of getting/setting a field and also 
show the cost of getting/setting a field multiple times.



##########
sdks/java/core/jmh/src/main/java/org/apache/beam/sdk/schemas/GetterBasedSchemaProviderBenchmark.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.schemas;
+
+import static org.apache.beam.sdk.schemas.RowBundles.ByteBufferBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.BytesBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.DateTimeBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.IntBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.MapOfIntBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.MapOfNestedIntBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.NestedBytesBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.NestedIntBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.StringBuilderBundle;
+import static org.apache.beam.sdk.schemas.RowBundles.StringBundle;
+
+import org.apache.beam.sdk.schemas.RowBundles.ArrayOfNestedStringBundle;
+import org.apache.beam.sdk.schemas.RowBundles.ArrayOfStringBundle;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.infra.Blackhole;
+
+/**
+ * Benchmarks for {@link GetterBasedSchemaProvider} on reading / writing 
fields based on {@link
+ * GetterBasedSchemaProvider#toRowFunction(TypeDescriptor) toRowFunction} / 
{@link
+ * GetterBasedSchemaProvider#fromRowFunction(TypeDescriptor) fromRowFunction}.
+ *
+ * <p>Each benchmark method invocation, depending on {@link RowBundle#action}, 
either reads a bundle

Review Comment:
   the comment needs updating



##########
sdks/java/core/jmh/src/main/java/org/apache/beam/sdk/schemas/RowBundle.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.schemas;
+
+import java.nio.charset.StandardCharsets;
+import java.util.function.Function;
+import org.apache.beam.sdk.transforms.SerializableFunction;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.RowWithGetters;
+import org.apache.beam.sdk.values.RowWithStorage;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.infra.Blackhole;
+
+/**
+ * Bundle of rows according to the configured {@link Factory} as input for 
benchmarks.
+ *
+ * <p>The rows are created during {@link #setup()} to exclude initialization 
costs from the
+ * measurement. To prevent unintended cache hits in {@link RowWithGetters}, a 
new bundle of rows
+ * must be generated before every invocation.
+ *
+ * <p>Setup per {@link Level#Invocation} has considerable drawbacks. Though, 
given that processing
+ * bundles of rows (n={@link #bundleSize}) takes well above 1 ms, each 
individual invocation can be
+ * adequately timestamped without risking generating wrong results.
+ */
+@State(Scope.Benchmark)
+public class RowBundle {
+  @SuppressWarnings("ImmutableEnumChecker") // false positive
+  public enum Action {
+    /**
+     * Write field to object using {@link
+     * GetterBasedSchemaProvider#fromRowFunction(TypeDescriptor)}.
+     *
+     * <p>Use {@link RowWithStorage} to bypass optimizations in RowWithGetters 
for writes.
+     */
+    WRITE(Factory::createWithStorage),
+
+    /**
+     * Read field from {@link RowWithGetters} provided by {@link
+     * GetterBasedSchemaProvider#toRowFunction(TypeDescriptor)}.
+     */
+    READ_ONCE(Factory::createWithGetter),
+
+    /**
+     * Repeatedly (3x) read field from {@link RowWithGetters} provided by 
{@link
+     * GetterBasedSchemaProvider#toRowFunction(TypeDescriptor)}.
+     */
+    READ_REPEATED(Factory::createWithGetter);
+
+    final Function<SchemaCoder<?>, Factory<Row>> factoryProvider;
+
+    Action(Function<SchemaCoder<?>, Factory<Row>> factoryProvider) {
+      this.factoryProvider = factoryProvider;
+    }
+  }
+
+  private static final SchemaRegistry REGISTRY = 
SchemaRegistry.createDefault();
+
+  private final SchemaCoder<?> coder;
+  private final SerializableFunction<Row, ?> fromRow;
+  private Factory<Row> factory;
+
+  protected Row[] rows;
+
+  @Param("100000")
+  int bundleSize;
+
+  @Param({"READ_REPEATED", "WRITE"})

Review Comment:
   ```suggestion
     @Param({"READ_ONCE", "READ_REPEATED", "WRITE"})
   ```



##########
sdks/java/core/jmh/src/main/java/org/apache/beam/sdk/schemas/package-info.java:
##########
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/** Benchmarks for the Java SDK schemas. */

Review Comment:
   ```suggestion
   /** Benchmarks for schemas. */
   ```



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