Commit 77447b0
[CELEBORN-2248] Implement lazy loading for columnar shuffle classes and skew shuffle method using static holder pattern
### What changes were proposed in this pull request?
This PR converts the static initialization of columnar shuffle class constructors
and skew shuffle method to lazy initialization using the initialization-on-demand
holder idiom (static inner class pattern) in SparkUtils.java.
Specifically, the following changes were made:
1. Introduced `ColumnarHashBasedShuffleWriterConstructorHolder` static inner class
to lazily initialize the constructor for ColumnarHashBasedShuffleWriter
2. Introduced `ColumnarShuffleReaderConstructorHolder` static inner class to lazily
initialize the constructor for CelebornColumnarShuffleReader
3. Introduced `CelebornSkewShuffleMethodHolder` static inner class to lazily
initialize the `isCelebornSkewedShuffle` method reference
4. Modified `createColumnarHashBasedShuffleWriter()`, `createColumnarShuffleReader()`,
and `isCelebornSkewShuffleOrChildShuffle()` methods to use the holder pattern for
lazy initialization
5. Added JavaDoc comments explaining the lazy loading mechanism
### Why are the changes needed?
The current implementation statically initializes columnar shuffle class constructors
and the skew shuffle method at SparkUtils class loading time, which means these
classes/methods are loaded regardless of whether they are actually used.
This lazy loading approach ensures that:
- Columnar shuffle classes are only loaded when actually needed (when
`celeborn.columnarShuffle.enabled` is true and the create methods are called)
- CelebornShuffleState class is only loaded when skew shuffle detection is needed
- Reduces unnecessary class loading overhead for users not using these features
- Improves startup performance and memory footprint
- Aligns with the conditional usage pattern already present in SparkShuffleManager
The static holder pattern (initialization-on-demand holder idiom) provides several
advantages:
- Thread-safe without explicit synchronization (guaranteed by JVM class loading mechanism)
- No synchronization overhead at runtime (no volatile reads or lock acquisition)
- Simpler and more concise code compared to double-checked locking
- Recommended by Effective Java (Item 83) for lazy initialization
### Does this PR resolve a correctness bug?
No, this is a performance optimization.
### Does this PR introduce any user-facing change?
No. This change only affects when certain classes are loaded internally.
The functionality and API remain unchanged.
### How was this patch tested?
- Code review to verify correct implementation of the initialization-on-demand holder pattern
- Verified that JVM class loading guarantees thread safety (JLS §12.4.2)
- Analyzed existing columnar shuffle and skew shuffle test coverage in the codebase
- The changes are backward compatible and don't alter functionality, only initialization timing
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>1 parent d30c02e commit 77447b0
File tree
1 file changed
+66
-47
lines changed- client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn
1 file changed
+66
-47
lines changedLines changed: 66 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
242 | 250 | | |
243 | 251 | | |
244 | 252 | | |
| |||
248 | 256 | | |
249 | 257 | | |
250 | 258 | | |
251 | | - | |
252 | | - | |
253 | | - | |
| 259 | + | |
| 260 | + | |
254 | 261 | | |
255 | 262 | | |
256 | 263 | | |
257 | 264 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
271 | 286 | | |
272 | 287 | | |
273 | 288 | | |
| |||
279 | 294 | | |
280 | 295 | | |
281 | 296 | | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
295 | 308 | | |
296 | 309 | | |
297 | 310 | | |
| |||
541 | 554 | | |
542 | 555 | | |
543 | 556 | | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
549 | 568 | | |
550 | 569 | | |
551 | | - | |
552 | | - | |
| 570 | + | |
| 571 | + | |
553 | 572 | | |
554 | 573 | | |
555 | 574 | | |
| |||
0 commit comments