Repository navigation
Commit af6dcff
authored
[opt](paimon) Reduce JNI read object allocations (apache#66244)
Problem Summary:
The Paimon JNI read path created a new PaimonColumnValue for every array element, map key/value, and struct field on every row. Timestamp conversions also resolved the session time zone per value and built redundant intermediate temporal objects. On wide nested data or large scan batches, these short-lived objects increase allocation rate and GC pressure.
For example, consider two consecutive ARRAY<INT> rows, [10, 20] and [30, 40]. Previously, reading the second row allocated two new wrappers even though the first row's wrappers had already been consumed. This PR keeps two position-specific wrappers and resets their record, index, Doris type, Paimon type, and time zone before reading the second row. This is safe because VectorColumn consumes the unpacked list synchronously before the scanner advances to another value.
The same invariant is applied separately to array elements, map keys, map values, and struct fields. Caches are lazy, grow only when needed, and only the current collection size or projected struct indexes are emitted, so shrinking collections cannot expose stale entries. Struct wrappers are cached by the original field index, preserving sparse/non-contiguous projection behavior fixed by apache#66223.
For temporal values, the session time-zone string is now parsed once into a ZoneId. A Paimon TIMESTAMP_LTZ epoch instant is converted directly into that zone instead of constructing UTC and target-zone intermediates. TIMESTAMPTZ uses Paimon's equivalent local representation directly instead of converting through Instant and UTC.
What changed?
Lazily reuse nested PaimonColumnValue wrappers across rows for arrays, maps, structs, and recursively nested values.
Reset all row-dependent state before a cached wrapper is reused.
Cache the parsed session ZoneId instead of resolving it for every value.
Remove redundant temporal conversion objects while preserving negative-epoch, nanosecond, and DST behavior.
Add unit coverage for wrapper identity reuse, growing/shrinking arrays, maps, sparse struct projections, nested arrays, DST, negative epoch, and nanosecond precision.
Local allocation and latency microbenchmark
Environment: Linux x86_64, Oracle JDK 17.0.16, Paimon 1.3.1. The benchmark ran latest master and this commit in separate worktrees on the same machine. Each case used 100,000 warmup iterations and 5 measured trials; the table reports medians. Collection cases ran 300,000 operations per trial, timestamp cases ran 1,000,000. Allocation was measured with ThreadMXBean; GC count/time was measured with GarbageCollectorMXBean. A full GC was requested before each measured trial and excluded from the reported GC delta.
The collection output lists were preallocated and cleared between operations to isolate allocation inside the Paimon value conversion path. Therefore these numbers are a focused Java microbenchmark, not an end-to-end query throughput claim.
Benchmark data shape and values:
ARRAY<INT>[16]: one GenericRow containing one GenericArray with [0, 1, ..., 15].
MAP<INT,BIGINT>[16]: one GenericRow containing one insertion-ordered GenericMap with {0: 0, 1: 1, ..., 15: 15}.
STRUCT<INT,STRING,BIGINT>: one binary row containing (10, "x", 100); all three fields are projected.
TIMESTAMP_LTZ(9): one fixed instant, 2024-03-10T10:30:00.123456789Z, read in session zone America/Los_Angeles. This date exercises the US DST transition day.
TIMESTAMPTZ(9): one fixed pre-epoch value, 1969-12-31T23:59:59.999999999Z, read in UTC.
Every benchmark operation rereads the same Paimon row/value. This intentionally removes file I/O, row construction, and table scan variability, and isolates the allocation/latency of PaimonColumnValue.unpack*() or timestamp conversion. The core collection loop is equivalent to:
values.clear(); // preallocated outside the measured loop
columnValue.unpackArray(values);
consume(values.get(0), values.get(15));
On master, each unpackArray call above creates 16 wrapper objects. With this PR, the warmup creates the 16 position-specific wrappers once and measured iterations only reset them. Map and struct use the same loop shape with separate key/value or projected-field output lists.
Case master alloc (B/op) PR alloc (B/op) Allocation reduction master time (ns/op) PR time (ns/op) Time reduction Median GC collections/trial
ARRAY<INT>[16] 512.03 0.03 99.99% 368.38 141.61 61.6% 2 → 0
MAP<INT,BIGINT>[16] 1232.03 208.03 83.1% 668.39 508.57 23.9% 2 → 1
STRUCT<INT,STRING,BIGINT> 128.03 32.03 75.0% 63.74 63.73 ~0% 0 → 0
TIMESTAMP_LTZ(9) 384.01 64.01 83.3% 156.25 57.88 63.0% 2 → 1
TIMESTAMPTZ(9) 200.01 48.01 76.0% 44.45 21.65 51.3% 1 → 0
The remaining map allocation comes primarily from Paimon's GenericMap.keyArray() / valueArray() materialization, which is unchanged by this PR. Struct latency is effectively unchanged while allocation drops by 75%.1 parent a73cdc0 commit af6dcff
3 files changed
Lines changed: 354 additions & 23 deletions
File tree
- fe/be-java-extensions/paimon-scanner/src
- main/java/org/apache/doris/paimon
- test/java/org/apache/doris/paimon
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
45 | 62 | | |
46 | 63 | | |
47 | 64 | | |
48 | 65 | | |
49 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
50 | 72 | | |
51 | 73 | | |
52 | 74 | | |
53 | 75 | | |
54 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
55 | 82 | | |
56 | 83 | | |
57 | 84 | | |
| |||
70 | 97 | | |
71 | 98 | | |
72 | 99 | | |
73 | | - | |
| 100 | + | |
74 | 101 | | |
75 | 102 | | |
76 | 103 | | |
| |||
142 | 169 | | |
143 | 170 | | |
144 | 171 | | |
145 | | - | |
146 | | - | |
| 172 | + | |
| 173 | + | |
147 | 174 | | |
148 | 175 | | |
149 | 176 | | |
| |||
152 | 179 | | |
153 | 180 | | |
154 | 181 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 182 | + | |
| 183 | + | |
159 | 184 | | |
160 | 185 | | |
161 | 186 | | |
162 | 187 | | |
163 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
164 | 194 | | |
165 | 195 | | |
166 | 196 | | |
| |||
171 | 201 | | |
172 | 202 | | |
173 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
174 | 209 | | |
175 | | - | |
176 | | - | |
177 | | - | |
| 210 | + | |
| 211 | + | |
178 | 212 | | |
| 213 | + | |
179 | 214 | | |
180 | 215 | | |
181 | 216 | | |
182 | 217 | | |
183 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
184 | 223 | | |
| 224 | + | |
| 225 | + | |
185 | 226 | | |
186 | | - | |
187 | | - | |
188 | | - | |
| 227 | + | |
| 228 | + | |
189 | 229 | | |
| 230 | + | |
190 | 231 | | |
| 232 | + | |
| 233 | + | |
191 | 234 | | |
192 | | - | |
193 | | - | |
194 | | - | |
| 235 | + | |
| 236 | + | |
195 | 237 | | |
| 238 | + | |
196 | 239 | | |
197 | 240 | | |
198 | 241 | | |
199 | 242 | | |
200 | 243 | | |
201 | 244 | | |
202 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
203 | 249 | | |
204 | | - | |
205 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
206 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
207 | 298 | | |
208 | 299 | | |
0 commit comments