fs2.Chunk
summary
Chunk is fs2’s immutable, strict sequence optimized for moving bytes around: multiple implementations (empty, singleton, array-backed slice, Java NIO view) to be memory-competitive with primitive arrays and avoid copies. Map uses an Array[Any] trick to avoid ClassTag in most APIs; concat struggled with specialization so a heuristic concat tagged plus a fallback was used (broke on Scala.js). Final solution adds a chunk-of-chunks with a lazily computed accumulated sizes index: first lookup is linear, subsequent lookups O(log m), worst case about n log n.
AI-written summary · about
chapters (22)
- 0:00Introduction to fs2 Chunks
- 1:27History of the Chunk Type
- 3:29The fs2 IO API
- 5:54Memory Efficiency and Tuning
- 7:36Defining the Chunk Trait
- 9:39Implementing Chunk Types
- 11:26Structural Sharing
- 13:13Array Slices Implementation
- 15:21Mapping over Chunks
- 17:34Map Challenges
- 19:56The Map Implementation
- 22:27Filtering Chunks
- 23:50Concatenation Strategies
- 25:48Concat Implementation
- 27:39The Uncons Pull
- 30:24Tagless Concat Experiment
- 32:41ScalaJS Challenges
- 34:38Queue Implementation
- 37:20Optimizing Lookup
- 39:46For-Each Quadratic Issue
- 42:12Binary Search Optimization
- 45:41Conclusion
