Commit 5dfd259
authored
## What's Changed
A significant number of ArrowBuf and BufferLedger objects are created
during certain workloads. Saving several bytes per instance could add up
to significant memory savings and reduced memory allocation expense and
garbage collection.
The id field, which was a sequential value used when logging object
information, is replaced with an identity hash code. This should still
allow enough information for debugging without the memory overhead.
There may be possible duplicate values but it shouldn't matter for
logging purposes.
Atomic fields can be replaced by a primitive and a static updater which
saves several bytes per instance.
### ArrowBuf
| Component | Before | After | Savings |
|-----------|--------|-------|---------|
| `idGenerator` (static) | `AtomicLong` | Removed | 24 bytes globally |
| `id` field (per instance) | `long` (8 bytes) | Removed | **8 bytes per
instance** |
| `getId()` | Returns `id` field | Returns
`System.identityHashCode(this)` | — |
### BufferLedger
| Component | Before | After | Savings |
|-----------|--------|-------|---------|
| `LEDGER_ID_GENERATOR` (static) | `AtomicLong` | Removed | 24 bytes
globally |
| `ledgerId` (per instance) | `long` (8 bytes) | Removed | **8 bytes per
instance** |
| `bufRefCnt` | `AtomicInteger` (24 bytes) | `volatile int` + static
updater | **20 bytes per instance** |
### Total Savings
| Scale | ArrowBuf | BufferLedger | Combined |
|-------|----------|--------------|----------|
| 100K | 800 KB | 2.8 MB | **~3.6 MB** |
| 1M | 8 MB | 28 MB | **~36 MB** |
| 10M | 80 MB | 280 MB | **~360 MB** |
### Benchmarking
I ran the added benchmark before and after the metadata trimming.
**Metadata Trimmed**
| Benchmark | Mode | Score | Error |Units|
|-------|----------|--------------|----------|----------|
|MemoryFootprintBenchmarks.measureAllocationPerformance | avgt | 456.831
|± 36.059 | us/op|
|MemoryFootprintBenchmarks.measureArrowBufMemoryFootprint | ss | 161.085
|± 35.596| ms/op|
|Created 100000 ArrowBuf instances. Heap memory used | sum | 35631520
bytes (33.98 MB) |0 |bytes|
|Average memory per ArrowBuf| sum | 356.32 bytes |0 |bytes|
**Previous Object Layout**
| Benchmark | Mode | Score | Error |Units|
|-------|----------|--------------|----------|----------|
|MemoryFootprintBenchmarks.measureAllocationPerformance | avgt | 466.171
|± 16.233 | us/op|
|MemoryFootprintBenchmarks.measureArrowBufMemoryFootprint | ss | 176.790
|± 17.943 |ms/op|
|Created 100000 ArrowBuf instances. Heap memory used | sum | 38817480
bytes (37.02 MB) |0 |bytes|
|Average memory per ArrowBuf| sum | 388.17 bytes |0 |bytes|
Closes #1038.
1 parent 41acbdc commit 5dfd259
File tree
4 files changed
+263
-39
lines changed- memory/memory-core/src/main/java/org/apache/arrow/memory
- performance/src/main/java/org/apache/arrow/memory
4 files changed
+263
-39
lines changedLines changed: 25 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
46 | | - | |
| 54 | + | |
47 | 55 | | |
48 | 56 | | |
49 | | - | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
67 | | - | |
| 75 | + | |
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
| |||
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
120 | | - | |
| 128 | + | |
121 | 129 | | |
122 | 130 | | |
123 | | - | |
| 131 | + | |
124 | 132 | | |
125 | | - | |
| 133 | + | |
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
| |||
166 | 174 | | |
167 | 175 | | |
168 | 176 | | |
169 | | - | |
| 177 | + | |
170 | 178 | | |
171 | 179 | | |
172 | 180 | | |
173 | 181 | | |
174 | 182 | | |
175 | 183 | | |
176 | 184 | | |
177 | | - | |
| 185 | + | |
178 | 186 | | |
179 | 187 | | |
180 | 188 | | |
| |||
214 | 222 | | |
215 | 223 | | |
216 | 224 | | |
217 | | - | |
| 225 | + | |
218 | 226 | | |
219 | 227 | | |
220 | 228 | | |
| |||
255 | 263 | | |
256 | 264 | | |
257 | 265 | | |
258 | | - | |
| 266 | + | |
259 | 267 | | |
260 | 268 | | |
261 | 269 | | |
| |||
274 | 282 | | |
275 | 283 | | |
276 | 284 | | |
277 | | - | |
| 285 | + | |
278 | 286 | | |
279 | 287 | | |
280 | 288 | | |
| |||
284 | 292 | | |
285 | 293 | | |
286 | 294 | | |
287 | | - | |
| 295 | + | |
288 | 296 | | |
289 | 297 | | |
290 | 298 | | |
| |||
293 | 301 | | |
294 | 302 | | |
295 | 303 | | |
296 | | - | |
| 304 | + | |
297 | 305 | | |
298 | 306 | | |
299 | 307 | | |
300 | | - | |
| 308 | + | |
301 | 309 | | |
302 | 310 | | |
303 | 311 | | |
304 | 312 | | |
305 | 313 | | |
306 | | - | |
| 314 | + | |
307 | 315 | | |
308 | 316 | | |
309 | 317 | | |
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | | - | |
61 | 59 | | |
62 | | - | |
| 60 | + | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
68 | 66 | | |
69 | 67 | | |
70 | | - | |
| 68 | + | |
| 69 | + | |
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
| |||
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
221 | | - | |
| 220 | + | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
1083 | | - | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
1084 | 1087 | | |
1085 | | - | |
| 1088 | + | |
1086 | 1089 | | |
1087 | 1090 | | |
1088 | | - | |
| 1091 | + | |
1089 | 1092 | | |
1090 | 1093 | | |
1091 | 1094 | | |
| |||
Lines changed: 14 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
| 475 | + | |
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
481 | | - | |
| 481 | + | |
482 | 482 | | |
483 | 483 | | |
484 | 484 | | |
| |||
0 commit comments