Result
Keeping the matrix out of R does not by itself make this implementation faster. The DuckTinyCC aggregate beats the built-in SQL grid at every qualified size, but exporting a complete dense matrix as SQL lists is still about four to five times slower than LDZip’s R-matrix endpoint. Consuming the same constructed columns inside C is much cheaper than exporting and retaining them as SQL values.
These measurements use DuckTinyCC commit
9ef15a1,
which copies a fixed-width LIST result with one memcpy per row; the
earlier build made several DuckDB C API calls per returned double. Both
SQL endpoints also no longer sort the finished columns by j: the
protocol retains j, vals, not a row order. Against the earlier
measurements, the 5,000-variant 16-bit TinyCC cell fell from 1,039.4 to
511.5 ms on one thread and from 734.1 to 424.3 ms on four, and the
4,000-variant 16-bit cell from 633.4 to 293.2 ms on one thread.
The protocol declares the workloads and budgets. The full dimension ladder contains 90 fresh measured processes, plus 15 for the 5,000-variant checkpoint. Each qualified process executes repeated complete operations for at least five measured seconds. Tables show the median and range of the three process-average latencies, not individual-operation medians. Peak RSS is the maximum of the three fresh processes, including runtime/setup and the final profiling operation.
Measurements at a glance
The graphs read archived receipts; they do not rerun engines. Exact values, failure statuses and admission results remain in the expandable data tables. The 5,000-variant timing checkpoint was measured only at 16 bits.
What the endpoints do
-
SQL grid: generate every requested
(i,j)cell, left-join selected Parquet correlations, float32-equivalent decode, zero fill, unit diagonal, and ordered column lists. -
TinyCC SQL matrix: aggregate compact selected cells by column,
construct each full double column in C, copy it into DuckDB’s
composite output and retain the complete
j, vals DOUBLE[]relation. -
LDZip R matrix:
fetchLD()returns the complete dense R matrix through its native reader.
Every timed operation constructs, fully consumes and releases the
result. SQL uses sum(list_sum(vals)); LDZip uses sum(m), without a
second full-matrix checksum temporary or forced GC per operation. R
orchestrates the SQL endpoints and receives only scalar metrics, not
matrix values. The two SQL endpoints are directly comparable; the LDZip
endpoint has a different output representation and is compatibility
context.
Dimension ladder
The fixed source is the public chr20 tutorial’s nested 4× region, at both quantizations. Requested dimensions grow 1,000 → 2,000 → 4,000 variants: 1×/2×/4× per axis, with 1×/4×/16× required dense output cells. This is not a file-row-count ladder. Repeated operations intentionally use warm OS cache and reused connections; first operations and setup costs are separately recorded in the raw evidence.
16-bit
| Variants | Bits | Endpoint | Threads | Warm mean ms: median [min, max] | Max RSS MiB | Status |
|---|---|---|---|---|---|---|
| 1000 | 16 | SQL grid | 1 | 178.2 [177.4, 179.4] | 250.6 | PASS |
| 1000 | 16 | TinyCC SQL matrix | 1 | 15.6 [15.6, 15.7] | 154.5 | PASS |
| 1000 | 16 | LDZip R matrix | 1 | 3.8 [3.8, 3.9] | 129.3 | PASS |
| 1000 | 16 | SQL grid | 4 | 93.9 [93.1, 94.2] | 495.0 | PASS |
| 1000 | 16 | TinyCC SQL matrix | 4 | 17.8 [17.4, 18.0] | 212.4 | PASS |
| 2000 | 16 | SQL grid | 1 | 743.9 [743.3, 745.4] | 474.3 | PASS |
| 2000 | 16 | TinyCC SQL matrix | 1 | 69.8 [66.7, 70.9] | 203.2 | PASS |
| 2000 | 16 | LDZip R matrix | 1 | 14.8 [14.8, 14.8] | 137.5 | PASS |
| 2000 | 16 | SQL grid | 4 | not qualified | 1032.3 | FAIL |
| 2000 | 16 | TinyCC SQL matrix | 4 | 76.9 [76.0, 77.0] | 301.9 | PASS |
| 4000 | 16 | SQL grid | 1 | not qualified | 977.4 | FAIL |
| 4000 | 16 | TinyCC SQL matrix | 1 | 293.2 [292.2, 293.8] | 329.7 | PASS |
| 4000 | 16 | LDZip R matrix | 1 | 76.1 [75.8, 76.1] | 198.5 | PASS |
| 4000 | 16 | SQL grid | 4 | not qualified | 927.0 | FAIL |
| 4000 | 16 | TinyCC SQL matrix | 4 | 253.2 [252.5, 255.6] | 531.6 | PASS |
8-bit
| Variants | Bits | Endpoint | Threads | Warm mean ms: median [min, max] | Max RSS MiB | Status |
|---|---|---|---|---|---|---|
| 1000 | 8 | SQL grid | 1 | 179.2 [179.0, 179.5] | 251.1 | PASS |
| 1000 | 8 | TinyCC SQL matrix | 1 | 15.5 [15.3, 15.5] | 154.6 | PASS |
| 1000 | 8 | LDZip R matrix | 1 | 3.8 [3.8, 3.8] | 129.6 | PASS |
| 1000 | 8 | SQL grid | 4 | 93.2 [91.7, 93.2] | 499.3 | PASS |
| 1000 | 8 | TinyCC SQL matrix | 4 | 17.4 [17.2, 17.5] | 212.3 | PASS |
| 2000 | 8 | SQL grid | 1 | 745.6 [742.9, 749.7] | 473.7 | PASS |
| 2000 | 8 | TinyCC SQL matrix | 1 | 68.1 [65.3, 70.3] | 203.6 | PASS |
| 2000 | 8 | LDZip R matrix | 1 | 14.6 [14.5, 14.6] | 137.1 | PASS |
| 2000 | 8 | SQL grid | 4 | not qualified | 973.2 | FAIL |
| 2000 | 8 | TinyCC SQL matrix | 4 | 76.6 [76.0, 76.8] | 302.3 | PASS |
| 4000 | 8 | SQL grid | 1 | not qualified | 978.2 | FAIL |
| 4000 | 8 | TinyCC SQL matrix | 1 | 290.4 [289.5, 291.4] | 331.0 | PASS |
| 4000 | 8 | LDZip R matrix | 1 | 75.1 [75.1, 75.2] | 198.7 | PASS |
| 4000 | 8 | SQL grid | 4 | not qualified | 927.4 | FAIL |
| 4000 | 8 | TinyCC SQL matrix | 4 | 252.3 [251.7, 253.4] | 530.4 | PASS |
At 2,000 variants/four threads, SQL completes but all six processes exceed the declared 879 MiB RSS ceiling. At 4,000 variants, SQL cannot construct the matrix within the 1 GiB DuckDB buffer limit. These cells do not receive qualified latency values. All TinyCC and LDZip matrix cells pass their declared resource budgets; qualified SQL profiles report no spill. Failed SQL allocations do not have valid completed profiles.
5,000-variant, 16-bit checkpoint
| Variants | Bits | Endpoint | Threads | Warm mean ms: median [min, max] | Max RSS MiB | Status |
|---|---|---|---|---|---|---|
| 5000 | 16 | SQL grid | 1 | not qualified | 1094.7 | FAIL |
| 5000 | 16 | TinyCC SQL matrix | 1 | 511.5 [509.6, 512.3] | 436.1 | PASS |
| 5000 | 16 | LDZip R matrix | 1 | 107.5 [106.3, 107.7] | 267.3 | PASS |
| 5000 | 16 | SQL grid | 4 | not qualified | 1494.7 | FAIL |
| 5000 | 16 | TinyCC SQL matrix | 4 | 424.3 [423.1, 425.9] | 681.1 | PASS |
The TinyCC matrix endpoint takes 511.5 ms on one thread or 424.3 ms on four threads; LDZip’s R endpoint takes 107.5 ms. Their maximum RSS values are 436.1, 681.1 and 267.3 MiB, respectively. The built-in SQL grid fails the 1 GiB buffer limit at both thread counts.
Native-buffer consumption diagnostic
This variant reuses the selected-cell state and the full C column constructor, consumes every double inside C, releases the temporary buffer, and returns only a scalar column checksum. It does not retain a complete matrix in SQL or R. Each thread count uses three fresh processes and at least five measured seconds per process under the same byte and wall ceilings.
| Threads | Mean ms: median [min, max] | Max RSS MiB | Max DuckDB buffer MiB | Spill bytes |
|---|---|---|---|---|
| 1 | 103.0 [101.9, 105.0] | 160.0 | 10.8 | 0 |
| 4 | 39.5 [35.3, 42.8] | 171.9 | 23.9 | 0 |
The matrix and checksum endpoints return different results. This diagnostic combines changes to composite-value export, buffer lifetime, SQL retention and consumption; it cannot attribute their individual costs or establish a matrix-export or GEMM speedup. It does show that TinyCC’s arithmetic alone is not the complete cost of the SQL matrix endpoint.
Correctness and native-library linkage
The admission checks compare every available output cell against independently decoded sparse values, including zero fill and the diagonal. TinyCC passes all 16 size/bit-depth/thread combinations through 5,000 variants. SQL passes the eight combinations at 1,000 and 2,000; the eight larger combinations are explicit resource failures, not parity passes. Both endpoints also match actual LDZip matrices exactly at 1,000 variants and both bit depths. Seeded empty columns, bad coordinates/quantization, visible NULL failure and a changed diagonal are checked separately from measured processes.
probe_blas_link.R passes all four entries of a small DGEMM using both
explicit BLAS linking and dlopen()/dlsym() of R’s actual OpenBLAS
0.3.26 provider. It uses R’s integer and Fortran character-length ABI
declarations; the real-only header shim avoids an unused C99 _Complex
declaration unsupported by TinyCC. This glibc exposes the dynamic-loader
symbols through libc. It is an ABI/linkage test on a small matrix, not
a GEMM performance measurement. TinyCC compiles the C glue; the linked
OpenBLAS provider supplies the numerical routine. No BLAS or SIMD
throughput was measured.
The actual measured environment is R 4.6.0, DuckDB R 1.5.5,
LDZipMatrix 1.0, Linux x86-64 on an Intel Core i5-13500. The
matrix endpoints used the DuckTinyCC build of commit 9ef15a1, SHA256
a3b2b4f88cbc529487aafc6e09e463cf1d1b2af567c9edb7e00409368e36440e. The
native-buffer diagnostic returns a scalar, not a list, and keeps its
earlier measurement with SHA256
30054a7da930905f7b530f0ba3c2dce8a1c3ea698c581c6cf7c9c227ed634b49.
Capabilities were checked in the loaded runtime. Input/source hashes,
complete settings, process metrics and profiles are retained with the
evidence.
Reproduce
Prepare the existing public-region artifacts with full_test.sh, and
provide a recent local DuckTinyCC build with aggregate support.
Compilation runs trusted, unsandboxed C. The installed community
extension may have different capabilities; the local artifact is
supplied explicitly.
cd demos/ldzip
export DUCKTINYCC_EXTENSION="$HOME/DuckTinyCC/build/release/ducktinycc.duckdb_extension"
Rscript --vanilla check_native.R
Rscript --vanilla measure_native.R
NATIVE_OUT_DIR=work/perf/native-checkpoint NATIVE_SIZES=5000 NATIVE_BITS=16 \
Rscript --vanilla measure_native.R
mkdir -p work/perf/native-boundary
for threads in 1 4; do
for rep in 1 2 3; do
stem="work/perf/native-boundary/t${threads}-r${rep}"
OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 timeout 60s \
/usr/bin/time -f '%e %M' -o "$stem.time" \
Rscript --vanilla probe_native_boundary.R "$threads" "$stem.json" \
> "$stem.log" 2>&1
done; done
OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 Rscript --vanilla probe_blas_link.R
Rscript --vanilla -e 'rmarkdown::render("NATIVE_REPORT.Rmd")'
The matrix suites exit nonzero because SQL budget failures are retained.
Inspect work/perf/native/raw.tsv,
work/perf/native-checkpoint/raw.tsv, work/perf/native-admission.tsv
and work/perf/native-boundary/raw.tsv; the scoped raw snapshots and
manifests are also in evidence/native.
Not measured
No end-to-end chunk-to-GEMM pipeline, SQL-to-R matrix handoff, cold-cache latency, downstream SuSiE run, whole-chromosome workload or optimized matrix-extension alternative is measured here. The timings characterize these specific queries and the generic TinyCC aggregate bridge, not the best possible DuckDB-native implementation.
Rducks’ public R batches copy values. A consumer that reads DuckDB chunks into a native buffer before that conversion, completing borrowed-vector access before chunk destruction, is proposed but not implemented.