Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DynamicWhereFilter performance #5293

Merged
merged 21 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9967890
Partial prototype of a fix, and some notes
rcaudy Mar 21, 2024
f31f509
Lots of changes but tests passing.
lbooker42 Mar 22, 2024
78f93aa
Merge pull request #12 from lbooker42/lab-wherein-tuple
rcaudy Mar 22, 2024
e061c46
Improve JavaDocs and correct default implementations in TupleExporter…
rcaudy Mar 22, 2024
250dfee
Corrections and some more work with new methods in TupleExporter
rcaudy Mar 25, 2024
871755a
Add missing SetInclusionKernel interface methods
rcaudy Mar 25, 2024
045751d
Add missing tupleLength implementations to TupleSourceCodeGenerator
rcaudy Mar 25, 2024
98ab1c1
Fixups to TupleSourceCodeGenerator to match TupleExporter
rcaudy Mar 25, 2024
3c69157
Regenerate TupleSources
rcaudy Mar 25, 2024
cd62afd
Some clean up to the offset mappings
rcaudy Mar 25, 2024
bb1d49c
Minor formatting
rcaudy Mar 25, 2024
f6a33f1
Merge pull request #16 from rcaudy/rwc-index-lookup-via-tuples
lbooker42 Mar 25, 2024
d0ba4c5
Improved (hopefully) code and expanded tests.
lbooker42 Mar 25, 2024
f6a3f04
Simplification in filterPartialIndex, bug fix
lbooker42 Mar 25, 2024
c195b50
Merge pull request #13 from lbooker42/lab-wherein-tuple
rcaudy Mar 26, 2024
7cd0e35
Some cleanup to filterLinear. Get rid of reliance on setKeySource, in…
rcaudy Mar 26, 2024
3a183a9
Get rid of liveValues. Get rid of reliance on ColumnSource.match() fo…
rcaudy Mar 26, 2024
18dde1b
Rename "matchPairs"
rcaudy Mar 26, 2024
1462537
Merge pull request #17 from rcaudy/rwc-index-lookup-via-tuples
lbooker42 Mar 26, 2024
f0d807a
Removed final TODO (and lambda optimization)
lbooker42 Mar 26, 2024
dede558
Merge pull request #14 from lbooker42/lab-wherein-tuple
rcaudy Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,33 @@ default T createTupleFromValues(@NotNull final Object... values) {
}

@Override
default <ELEMENT_TYPE> void exportElement(final T tuple, final int elementIndex,
@FinalDefault
default int tupleLength() {
return 1;
}

@Override
@FinalDefault
default <ELEMENT_TYPE> void exportElement(@NotNull final T tuple, final int elementIndex,
@NotNull final WritableColumnSource<ELEMENT_TYPE> writableSource, final long destinationIndexKey) {
// noinspection unchecked
writableSource.set(destinationIndexKey, (ELEMENT_TYPE) tuple);
}

@Override
default Object exportElement(T tuple, int elementIndex) {
@FinalDefault
default Object exportElement(@NotNull final T tuple, final int elementIndex) {
Require.eqZero(elementIndex, "elementIndex");
return tuple;
}

@Override
@FinalDefault
default void exportAllTo(final Object @NotNull [] dest, @NotNull final T tuple) {
Require.geqZero(dest.length, "dest.length");
dest[0] = tuple;
}

@Override
ColumnSource<T> getPrevSource();

Expand Down
131 changes: 115 additions & 16 deletions engine/api/src/main/java/io/deephaven/engine/table/TupleExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@

/**
* Interface for classes that know how to export the elements of a given tuple type. Currently, supports element-wise
* export to a {@link WritableColumnSource} without unnecessary boxing.
* export to a {@link WritableColumnSource} without unnecessary boxing, and possibly-boxing export as {code Object}.
*/
public interface TupleExporter<TUPLE_TYPE> {

/**
* Get the number of elements in tuples supported by this TupleExporter.
*
* @return The number of elements in tuples supported by this TupleExporter
*/
int tupleLength();

/**
* Export a single element from the tuple, identified by its element index, to the destination row key of the
* supplied writable source.
Expand All @@ -26,39 +33,131 @@ public interface TupleExporter<TUPLE_TYPE> {
* @param writableSource The destination
* @param destinationIndexKey The destination row key
*/
<ELEMENT_TYPE> void exportElement(TUPLE_TYPE tuple, int elementIndex,
@NotNull WritableColumnSource<ELEMENT_TYPE> writableSource, long destinationIndexKey);
<ELEMENT_TYPE> void exportElement(
@NotNull TUPLE_TYPE tuple,
int elementIndex,
@NotNull WritableColumnSource<ELEMENT_TYPE> writableSource,
long destinationIndexKey);

/**
* Export a single element from the tuple, identified by its element index, to an Object
*
* Export a single element (identified by {@code elementIndex}) from the tuple, boxing as necessary.
* <p>
* For the empty tuple, this is unsupported.
* <p>
* For singles, this will copy the sole element, possibly in boxed form.
* <p>
* For doubles and longer, this will copy the specified element without any unnecessary boxing.
*
* @param tuple The tuple to export an element from
* @param elementIndex The element index to export
* @return The exported element, boxed when necessary
*/
Object exportElement(TUPLE_TYPE tuple, int elementIndex);
Object exportElement(@NotNull TUPLE_TYPE tuple, int elementIndex);

/**
* Export a single element from the tuple, identified by its element index, to an Object. If the tuple has been
* internally reinterpreted, return the reinterpreted value.
*
* Fill an {@code Object[]} with all elements from the tuple, boxing as necessary.
* <p>
* For the empty tuple, this is unsupported.
*
* @param dest The destination {@code Object[]}
* @param tuple The tuple to export from
*/
default void exportAllTo(final Object @NotNull [] dest, @NotNull final TUPLE_TYPE tuple) {
final int length = tupleLength();
for (int ei = 0; ei < length; ++ei) {
dest[ei] = exportElement(tuple, ei);
}
}

/**
* Fill an {@code Object[]} with all elements from the tuple, boxing as necessary, mapping the tuple elements to the
* destination array using the provided {@code int[]} {code map}. This map contains the destination index for each
* tuple element in order.
* <p>
* For singles, this will copy the sole element, possibly in boxed form.
* Providing {@code map = new int{1, 2, 0}} means that the 0th element of the tuple will be written in
* {@code dest[1]}, the 1st element of the tuple will be written in {@code dest[2]}, and the 2nd element of the
* tuple will be written in {@code dest[0]}.
* <p>
* For doubles and longer, this will copy the specified element without any unnecessary boxing.
* For the empty tuple, this is unsupported.
*
* @param dest The destination {@code Object[]}
* @param tuple The tuple to export from
* @param map Instructions where to write each tuple element in {@code dest}
*/
default void exportAllTo(
final Object @NotNull [] dest,
@NotNull final TUPLE_TYPE tuple,
final int @NotNull [] map) {
final int length = tupleLength();
for (int ei = 0; ei < length; ++ei) {
dest[map[ei]] = exportElement(tuple, ei);
}
}

/**
* Export a single element (identified by {@code elementIndex}) from the tuple, boxing as necessary. If the tuple
* has been internally reinterpreted, return the reinterpreted value.
* <p>
* For the empty tuple, this is unsupported.
*
* @param tuple The tuple to export an element from
* @param elementIndex The element index to export
* @return The exported element, reinterpreted if internally reinterpreted, boxed when necessary
*/
default Object exportElementReinterpreted(TUPLE_TYPE tuple, int elementIndex) {
default Object exportElementReinterpreted(@NotNull final TUPLE_TYPE tuple, final int elementIndex) {
return exportElement(tuple, elementIndex);
}

/**
* Fill an {@code Object[]} with all element from the tuple, boxing as necessary. If the tuple has been internally
* reinterpreted, will fill with reinterpreted values.
* <p>
* For the empty tuple, this is unsupported.
*
* @param dest The destination {@code Object[]}
* @param tuple The tuple to export from
*/
default void exportAllReinterpretedTo(final Object @NotNull [] dest, @NotNull final TUPLE_TYPE tuple) {
final int length = tupleLength();
for (int ei = 0; ei < length; ++ei) {
dest[ei] = exportElementReinterpreted(tuple, ei);
}
}

/**
* Fill an Object[] with all element from the tuple, boxing as necessary, mapping the tuple elements to the
* destination array using the provided int[] map. This map contains the destination index for each tuple element in
* order. will fill with reinterpreted values.
* <p>
* Providing {@code map = new int{1, 2, 0}} means that the 0th element of the tuple will be written in
* {@code dest[1]}, the 1st element of the tuple will be written in {@code dest[2]}, and the 2nd element of the
* tuple will be written in {@code dest[0]}.
* <p>
* For the empty tuple, this is unsupported.
*
* @param dest The destination {@code Object[]}
* @param tuple The tuple to export from
* @param map Instructions where to write each tuple element in {@code dest}
*/
default void exportAllReinterpretedTo(
final Object @NotNull [] dest,
@NotNull final TUPLE_TYPE tuple,
final int @NotNull [] map) {
final int length = tupleLength();
for (int ei = 0; ei < length; ++ei) {
dest[map[ei]] = exportElementReinterpreted(tuple, ei);
}
}

@FunctionalInterface
interface ExportElementFunction<TUPLE_TYPE> {

/**
* Export a single element from the tuple, identified by its element index, to an Object. This interface is
* intended to be compatible with both {@link TupleExporter#exportElement(Object, int)} and
* {@link TupleExporter#exportElementReinterpreted(Object, int)}, and consequently does not specify whether the
* result will be reinterpreted.
*
* @param tuple The tuple to export an element from
* @param elementIndex The element index to export
* @return The exported element, boxed when necessary
*/
Object exportElement(@NotNull TUPLE_TYPE tuple, int elementIndex);
}
}
Loading
Loading