skip to main content
10.1145/3009837.3009880acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
research-article

Stream fusion, to completeness

Published:01 January 2017Publication History

ABSTRACT

Stream processing is mainstream (again): Widely-used stream libraries are now available for virtually all modern OO and functional languages, from Java to C# to Scala to OCaml to Haskell. Yet expressivity and performance are still lacking. For instance, the popular, well-optimized Java 8 streams do not support the zip operator and are still an order of magnitude slower than hand-written loops.

We present the first approach that represents the full generality of stream processing and eliminates overheads, via the use of staging. It is based on an unusually rich semantic model of stream interaction. We support any combination of zipping, nesting (or flat-mapping), sub-ranging, filtering, mapping—of finite or infinite streams. Our model captures idiosyncrasies that a programmer uses in optimizing stream pipelines, such as rate differences and the choice of a “for” vs. “while” loops. Our approach delivers hand-written–like code, but automatically. It explicitly avoids the reliance on black-box optimizers and sufficiently-smart compilers, offering highest, guaranteed and portable performance.

Our approach relies on high-level concepts that are then readily mapped into an implementation. Accordingly, we have two distinct implementations: an OCaml stream library, staged via MetaOCaml, and a Scala library for the JVM, staged via LMS. In both cases, we derive libraries richer and simultaneously many tens of times faster than past work. We greatly exceed in performance the standard stream libraries available in Java, Scala and OCaml, including the well-optimized Java 8 streams.

References

  1. Reactive extensions, 2016.Google ScholarGoogle Scholar
  2. A. Biboudis, N. Palladinos, and Y. Smaragdakis. Clash of the Lambdas. arXiv preprint arXiv:1406.6631, 9th International Workshop on Implementation, Compilation, Optimization of Object-Oriented Languages, Programs and Systems, 2014.Google ScholarGoogle Scholar
  3. A. Biboudis, N. Palladinos, G. Fourtounis, and Y. Smaragdakis. Streams a la carte: Extensible Pipelines with Object Algebras. In 29th European Conference on Object-Oriented Programming (ECOOP 2015), volume 37, pages 591–613, 2015. ISBN 978-3-939897-86-6.Google ScholarGoogle Scholar
  4. A. Bondorf. Improving binding times without explicit CPSconversion. In Lisp & Functional Programming, pages 1–10, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. D. Coutts, R. Leshchinskiy, and D. Stewart. Stream fusion: From lists to streams to nothing at all. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, ICFP ’07, pages 315–326, New York, NY, USA, 2007. ACM. ISBN 978- 1-59593-815-2. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. A. Farmer, A. Gill, E. Komp, and N. Sculthorpe. The HERMIT in the Machine: A Plugin for the Interactive Transformation of GHC Core Language Programs. In Proceedings of the 2012 Haskell Symposium, Haskell ’12, pages 1–12, New York, NY, USA, 2012. ACM. ISBN 978-1-4503-1574-6. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. A. Farmer, C. Hoener zu Siederdissen, and A. Gill. The HERMIT in the Stream: Fusing Stream Fusion’s concatMap. In Proceedings of the ACM SIGPLAN 2014 Workshop on Partial Evaluation and Program Manipulation, PEPM ’14, pages 97–108, New York, NY, USA, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. ACM. ISBN 978-1-4503-2619-3.Google ScholarGoogle Scholar
  9. J. Gibbons and G. Jones. The under-appreciated unfold. In ICFP ’98: Proceedings of the ACM International Conference on Functional Programming, volume 34(1), pages 273–279, New York, Sept. 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. ACM Press.Google ScholarGoogle Scholar
  11. A. Gill, J. Launchbury, and S. L. Peyton Jones. A short cut to deforestation. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, FPCA ’93, pages 223–232, New York, NY, USA, 1993. ACM. ISBN 0-89791-595-X. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. N. Halbwachs, P. Caspi, P. Raymond, and D. Pilaud. The synchronous data flow programming language LUSTRE. Proceedings of the IEEE, 79(9):1305–1320, 1991.Google ScholarGoogle ScholarCross RefCross Ref
  13. J. Inoue and W. Taha. Reasoning about multi-stage programs. In ESOP, volume 7211 of Lecture Notes in Computer Science, pages 357–376. Springer, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. M. Jonnalagedda and S. Stucki. Fold-based Fusion As a Library: A Generative Programming Pearl. In Proceedings of the 6th ACM SIGPLAN Symposium on Scala, SCALA 2015, pages 41–50, New York, NY, USA, 2015. ACM. ISBN 978-1-4503-3626-0. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. G. Keller, M. M. Chakravarty, R. Leshchinskiy, S. Peyton Jones, and B. Lippmeier. Regular, shape-polymorphic, parallel arrays in Haskell. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming, ICFP ’10, pages 261–272, New York, NY, USA, 2010. ACM. ISBN 978-1-60558-794-3. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. R. Kelsey and P. Hudak. Realistic compilation by program transformation (detailed summary). In Proceedings of the 16th ACM SIGPLANSIGACT Symposium on Principles of Programming Languages, POPL ’89, pages 281–292, New York, NY, USA, 1989. ACM. ISBN 0- 89791-294-2. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. P. Khuong. Introducing pipes, a lightweight stream fusion edsl, 2011.Google ScholarGoogle Scholar
  18. O. Kiselyov. Iteratees. In FLOPS, volume 7294 of LNCS, pages 166– 181. Springer, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. O. Kiselyov. The Design and Implementation of BER MetaOCaml. In Functional and Logic Programming, pages 86–102. Springer, 2014.Google ScholarGoogle Scholar
  20. B. Lippmeier, M. M. Chakravarty, G. Keller, and A. Robinson. Data flow fusion with series expressions in Haskell. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Haskell ’13, pages 93– 104, New York, NY, USA, 2013. ACM. ISBN 978-1-4503-2383-3. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. G. Mainland, R. Leshchinskiy, and S. Peyton Jones. Exploiting vector instructions with generalized stream fusion. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP ’13, pages 37–48, New York, NY, USA, 2013. ACM. ISBN 978-1-4503-2326-0. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. E. Meijer, M. Fokkinga, and R. Paterson. Functional programming with bananas, lenses, envelopes and barbed wire. In J. Hughes, editor, Functional Programming Languages and Computer Architecture: 5th Conference, number 523 in Lecture Notes in Computer Science, pages 124–144, Berlin, 1991. The Association for Computing Machinery, Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. D. G. Murray, M. Isard, and Y. Yu. Steno: automatic optimization of declarative queries. In ACM SIGPLAN Notices, volume 46, pages 121–131. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. N. Palladinos and K. Rontogiannis. LinqOptimizer: An automatic query optimizer for LINQ to Objects and PLINQ. Technical report, Nessos Information Technologies S.A., 2013.Google ScholarGoogle Scholar
  25. S. Peyton Jones, A. Tolmach, and T. Hoare. Playing by the rules: rewriting as a practical optimisation technique in GHC. In Haskell workshop, volume 1, pages 203–233, 2001.Google ScholarGoogle Scholar
  26. M. Pouzet. Lucid synchrone, version 3. Tutorial and reference manual. Université Paris-Sud, LRI, 2006.Google ScholarGoogle Scholar
  27. A. Prokopec and D. Petrashko. ScalaBlitz: Lightning-fast Scala collections framework. Technical report, LAMP Scala Team, EPFL, 2013.Google ScholarGoogle Scholar
  28. T. Rompf and M. Odersky. Lightweight modular staging: A pragmatic approach to runtime code generation and compiled dsls. Commun. ACM, 55(6):121–130, June 2012. ISSN 0001-0782. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. T. Rompf, A. K. Sujeeth, N. Amin, K. J. Brown, V. Jovanovic, H. Lee, M. Jonnalagedda, K. Olukotun, and M. Odersky. Optimizing data structures in high-level programs: New directions for extensible compilers based on staging. In Proceedings of the 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’13, pages 497–510, New York, NY, USA, 2013. ACM. ISBN 978-1-4503-1832-7. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. M. Shaw, W. A. Wulf, and R. L. London. Abstraction and verification in Alphard: defining and specifying iteration and generators. Communications of the ACM, 20(8):553–564, 1977. Google ScholarGoogle Scholar
  32. A. Shipilev, S. Kuksenko, A. Astrand, S. Friberg, and H. Loef. OpenJDK: jmh.Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. M. H. B. Sørensen, R. Glück, and N. D. Jones. Towards unifying deforestation, supercompilation, partial evaluation, and generalized partial computation. In D. Sannella, editor, Programming Languages and Systems: Proceedings of ESOP'94, 5th European Symposium on Programming, number 788 in Lecture Notes in Computer Science, pages 485-500, Berlin, 11-13 Apr. 1994. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. G. Stewart, M. Gowda, G. Mainland, B. Radunovic, D. Vytiniotis, and C. L. Agullo. Ziria: A DSL for wireless systems programming. In Proceedings of the Twentieth International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS ’15, pages 415–428, New York, NY, USA, 2015. ACM. ISBN 978-1-4503-2835-7. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. J. Svenningsson. Shortcut fusion for accumulating parameters & ziplike functions. In Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming, ICFP ’02, pages 124–132, New York, NY, USA, 2002. ACM. ISBN 1-58113-487- 8. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. B. J. Svensson and J. Svenningsson. Defunctionalizing Push Arrays. In Proceedings of the 3rd ACM SIGPLAN Workshop on Functional High-performance Computing, FHPC ’14, pages 43–52, New York, NY, USA, 2014. ACM. ISBN 978-1-4503-3040-4. Google ScholarGoogle Scholar
  37. W. Taha. A Gentle Introduction to Multi-stage Programming. In C. Lengauer, D. Batory, C. Consel, and M. Odersky, editors, Domain-Specific Program Generation, number 3016 in Lecture Notes in Computer Science, pages 30–50. Springer Berlin Heidelberg, 2004. ISBN 978-3-540-22119-7 978-3-540-25935-0.Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. P. L. Wadler. Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science, 73(2):231–248, June 1990. Google ScholarGoogle Scholar
  39. R. C. Waters. User manual for the series macro package. MIT AI Memo 1082, 1989.Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. R. C. Waters. Automatic transformation of series expressions into loops. ACM Trans. Program. Lang. Syst., 13(1):52–98, Jan. 1991. ISSN 0164-0925. Google ScholarGoogle Scholar

Index Terms

  1. Stream fusion, to completeness

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in
      • Published in

        cover image ACM Conferences
        POPL '17: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages
        January 2017
        901 pages
        ISBN:9781450346603
        DOI:10.1145/3009837

        Copyright © 2017 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 1 January 2017

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        Overall Acceptance Rate824of4,130submissions,20%

        Upcoming Conference

        POPL '25

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader