logo CCISEL
  • Home
  • Team
  • Academia
  • News
  • Archive
  • Contacts
  

Spliterator is not only about parallelism

June 5, 2020 | Miguel Gamboa

Many are still mistaken about the purpose of Spliterator. It is not only about parallelism. Spliterator is the core traversing mechanism of Java Streams, regardless of being processed in parallel or sequentially. Whenever you build a Stream from an Iterator you are wrapping it around a Spliterator and incurring in useless indirections. Remember the answer stated by Bryan Goetz (author of Java streams) to the question of Miguel Gamboa about the choice between Iterator or Stream regarding laziness in a domain model design, namely:

  • “Spliterator has fundamentally lower per-element access costs than _Iterator, even sequentially._”
    1. ” The Iterator protocol is fundamentally less efficient.”
    2. “Spliterator further offers a “fast-path” iteration”

Iterator versus Stream

Copyright © CCISEL 2025