Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,14 @@ class BeamModulePlugin implements Plugin<Project> {
// that ends up on the runtime classpath.
args 'org.apache.beam'
}
args '-i=3'
args '-wi=3'
args '-f=3'
args '-r=20s'
args '-gc=true'

args '-foe=true'
args '-rf=json'
}

// Single shot of JMH benchmarks ensures that they can execute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,41 @@ public class RowWithGetters extends Row {
private final Factory<List<FieldValueGetter>> fieldValueGetterFactory;
private final Object getterTarget;
private final List<FieldValueGetter> getters;
private final boolean useCache;

private final Map<Integer, Collection> cachedCollections = Maps.newHashMap();
private final Map<Integer, Iterable> cachedIterables = Maps.newHashMap();
private final Map<Integer, Map> cachedMaps = Maps.newHashMap();
private Map<Integer, Collection> cachedCollections = null;
private Map<Integer, Iterable> cachedIterables = null;
private Map<Integer, Map> cachedMaps = null;

private void initCache() {
cachedCollections = Maps.newHashMap();
cachedIterables = Maps.newHashMap();
cachedMaps = Maps.newHashMap();
}

RowWithGetters(
Schema schema, Factory<List<FieldValueGetter>> getterFactory, Object getterTarget) {
super(schema);
this.fieldValueGetterFactory = getterFactory;
this.getterTarget = getterTarget;
this.getters = fieldValueGetterFactory.create(getterTarget.getClass(), schema);
this.useCache = schema.getOptions().hasOption("nocache") == false;
}

@Override
@SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"})
public <T> @Nullable T getValue(int fieldIdx) {
// lazy init cache on first getValue to include initialization costs into benchmark
if (cachedCollections == null) {
initCache();
}
Field field = getSchema().getField(fieldIdx);
FieldType type = field.getType();
Object fieldValue = getters.get(fieldIdx).get(getterTarget);
if (fieldValue == null && !field.getType().getNullable()) {
throw new RuntimeException("Null value set on non-nullable field " + field);
}
return fieldValue != null ? getValue(type, fieldValue, fieldIdx) : null;
return fieldValue != null ? getValue(type, fieldValue, useCache ? fieldIdx : null) : null;
}

private Collection getCollectionValue(FieldType elementType, Object fieldValue) {
Expand Down
Loading