Skip to content

Commit 977a529

Browse files
dfa1claude
andcommitted
refactor: remove Encoding.decodeSegment(), fix benchmark
Drop the default decodeSegment() method from Encoding — inline ArraySegments.of(decode(ctx)) at the one call site in EncodingRegistry. Fix RustWritesJavaReadsBigFileBenchmark using removed arr.buffer(0). Add API design principle to CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bb7b656 commit 977a529

5 files changed

Lines changed: 9 additions & 26 deletions

File tree

CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ In every module `pom.xml`, dependencies are grouped with comments:
168168

169169
Omit a section if empty (e.g. integration module has no production deps; performance has no test deps).
170170

171+
## API design
172+
173+
- Keep public interfaces as small as possible.
174+
- Don't expose internals. When in doubt, leave it out or make it private.
175+
171176
## Code style
172177

173178
- indents are 4 spaces, enforced by checkstyle

core/src/main/java/io/github/dfa1/vortex/encoding/DecodeContext.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ public Array decodeChild(int i, DType dtype, long rowCount) {
5555

5656
/// Recursively decode child {@code i} and return its primary backing segment.
5757
///
58-
/// <p>Equivalent to {@code decodeChild(i).segment()} but routes through
59-
/// {@link Encoding#decodeSegment(DecodeContext)} to avoid the deprecated
60-
/// {@link io.github.dfa1.vortex.core.array.Array#segment()} interface method.
61-
///
6258
/// @param i zero-based child index within this node's children array
6359
/// @return the primary {@link MemorySegment} of the decoded child
6460
public MemorySegment decodeChildSegment(int i) {
@@ -69,10 +65,6 @@ public MemorySegment decodeChildSegment(int i) {
6965

7066
/// Recursively decode child {@code i} with an explicit dtype and row count, returning its primary segment.
7167
///
72-
/// <p>Equivalent to {@code decodeChild(i, dtype, rowCount).segment()} but routes through
73-
/// {@link Encoding#decodeSegment(DecodeContext)} to avoid the deprecated
74-
/// {@link io.github.dfa1.vortex.core.array.Array#segment()} interface method.
75-
///
7668
/// @param i zero-based child index within this node's children array
7769
/// @param dtype logical type to assign to the child context
7870
/// @param rowCount number of logical rows for the child

core/src/main/java/io/github/dfa1/vortex/encoding/Encoding.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import io.github.dfa1.vortex.core.DType;
44
import io.github.dfa1.vortex.core.array.Array;
5-
import io.github.dfa1.vortex.core.array.ArraySegments;
6-
7-
import java.lang.foreign.MemorySegment;
85

96
/// Combines encode and decode for one encoding type.
107
/// Register via [EncodingRegistry] — implementations are discoverable via ServiceLoader.
@@ -34,19 +31,6 @@ public interface Encoding {
3431
/// @return encode result containing the root node, buffers, and optional stats
3532
EncodeResult encode(DType dtype, Object data, EncodeContext ctx);
3633

37-
/// Decodes this encoding and returns the primary backing segment of the result.
38-
///
39-
/// <p>Default implementation decodes via {@link #decode(DecodeContext)} and extracts
40-
/// the segment via {@link ArraySegments#of(Array)}. Override for efficiency if the
41-
/// internal decode can return the buffer directly.
42-
///
43-
/// @param ctx decoding context
44-
/// @return the primary {@link MemorySegment} of the decoded array
45-
/// @throws io.github.dfa1.vortex.core.VortexException if this encoding produces no primary segment
46-
default MemorySegment decodeSegment(DecodeContext ctx) {
47-
return ArraySegments.of(decode(ctx));
48-
}
49-
5034
/// Cascade-aware encode: returns a partial step with open child slots.
5135
/// Default wraps the terminal {@link #encode} result; override to expose children.
5236
///

core/src/main/java/io/github/dfa1/vortex/encoding/EncodingRegistry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.dfa1.vortex.core.VortexException;
44
import io.github.dfa1.vortex.core.array.Array;
5+
import io.github.dfa1.vortex.core.array.ArraySegments;
56
import io.github.dfa1.vortex.core.array.UnknownArray;
67

78
import java.lang.foreign.MemorySegment;
@@ -129,7 +130,7 @@ MemorySegment decodeAsSegment(DecodeContext ctx) {
129130
case UnknownArrayNode _ -> null;
130131
};
131132
if (encoding != null) {
132-
return encoding.decodeSegment(ctx);
133+
return ArraySegments.of(encoding.decode(ctx));
133134
}
134135
String id = switch (node) {
135136
case KnownArrayNode k -> k.encodingId().id();

performance/src/main/java/io/github/dfa1/vortex/performance/RustWritesJavaReadsBigFileBenchmark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import dev.vortex.arrow.ArrowAllocation;
1010
import dev.vortex.jni.NativeLoader;
1111
import io.github.dfa1.vortex.core.array.Array;
12+
import io.github.dfa1.vortex.core.array.ArraySegments;
1213
import io.github.dfa1.vortex.encoding.EncodingRegistry;
1314
import io.github.dfa1.vortex.io.VortexReader;
1415
import io.github.dfa1.vortex.scan.ScanResult;
@@ -178,7 +179,7 @@ private long scanJava() throws IOException {
178179
while (iter.hasNext()) {
179180
ScanResult r = iter.next();
180181
Array arr = r.columns().get("c0");
181-
MemorySegment buf = arr.buffer(0);
182+
MemorySegment buf = ArraySegments.of(arr);
182183
long count = buf.byteSize() / Long.BYTES;
183184
for (long i = 0; i < count; i++) {
184185
sum += buf.getAtIndex(LE_LONG, i);

0 commit comments

Comments
 (0)