Commit 52e1bf1
[SPARK-59431][CORE] Use ArrayList instead of LinkedList for BytesToBytesMap dataPages
`BytesToBytesMap` tracked its allocated data pages in a `LinkedList<MemoryBlock>`. Every
operation on this field is an append at the end, a full iteration, an operation at the end
(peek/remove last), or an index access -- there are no head or middle insertions/removals.
That access pattern fits `ArrayList` better than `LinkedList`: contiguous storage (better
iteration locality), no per-page `Node` allocation, and O(1) `get(index)` (used in the
destructive `MapIterator` page advance).
Change `dataPages` to an `ArrayList`. The `getLast()` / `removeLast()` calls (in `spill()`
and `reset()`) are `SequencedCollection` methods available on `ArrayList` only since Java 21;
since Spark supports Java 17 they are rewritten to `get(size() - 1)` / `remove(size() - 1)`
(both O(1) for the last element). The `free()` drain, which used `Iterator.remove()` (O(n^2)
on an `ArrayList`), is rewritten to remove from the end in a loop (O(n)), matching `reset()`.
The sibling field `spillWriters` genuinely uses FIFO front removal (`getFirst()` /
`removeFirst()`) and remains a `LinkedList`; only `dataPages` changes.
No user-facing change: identical behavior; thread-safety is unchanged (access is guarded by
the same external `synchronized` blocks).
Generated-by: Claude Opus 4.8
Co-authored-by: Isaac <no-reply@databricks.com>1 parent 0edaeb8 commit 52e1bf1
1 file changed
Lines changed: 8 additions & 9 deletions
Lines changed: 8 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
106 | | - | |
| 107 | + | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
413 | 414 | | |
414 | 415 | | |
415 | 416 | | |
416 | | - | |
| 417 | + | |
417 | 418 | | |
418 | 419 | | |
419 | 420 | | |
| |||
435 | 436 | | |
436 | 437 | | |
437 | 438 | | |
438 | | - | |
| 439 | + | |
439 | 440 | | |
440 | 441 | | |
441 | 442 | | |
| |||
1030 | 1031 | | |
1031 | 1032 | | |
1032 | 1033 | | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
| 1034 | + | |
| 1035 | + | |
1037 | 1036 | | |
1038 | 1037 | | |
1039 | 1038 | | |
| |||
1115 | 1114 | | |
1116 | 1115 | | |
1117 | 1116 | | |
1118 | | - | |
| 1117 | + | |
1119 | 1118 | | |
1120 | 1119 | | |
1121 | 1120 | | |
| |||
0 commit comments