Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ITERATORS+GENERATORS: THE ROAD TO VIRTUAL INFINITE RAM

ITERATORS+GENERATORS: THE ROAD TO VIRTUAL INFINITE RAM

Alexandre Daubois

March 29, 2024
Tweet

More Decks by Alexandre Daubois

Other Decks in Technology

Transcript

  1. Alexandre Daubois - Dutch PHP Conference 2024 - Amsterdam The

    Road To Virtual Infinite RAM Iterators & Generators
  2. Alexandre Daubois (@alexdaubois) Symfony Lead Developer at WanadevDigital, France One

    of the main contributors to Symfony (code+docs) Conference speaker, blogpost and book author (7th time in the Netherlands 🇳🇱)
  3. A B C D E A container of n elements,

    which could be stored...
  4. AppendIterator ArrayIterator CachingIterator CallbackFilterIterator DirectoryIterator EmptyIterator FilesystemIterator FilterIterator GlobIterator In

    fi niteIterator IteratorIterator LimitIterator MultipleIterator NoRewindIterator ParentIterator RecursiveArrayIterator RecursiveCachingIterator RecursiveCallbackFilterIterator RecursiveDirectoryIterator RecursiveFilterIterator RecursiveIteratorIterator RecursiveRegexIterator RecursiveTreeIterator RegexIterator
  5. What if the data source is… 1 billion elements in

    a remote cache? A fi le of 1 TB? A streamed video? An HTTP response of 800MB?
  6. Nikita Popov, Generators RFC For small ranges (around one hundred

    elements), [...] generators are slightly slower than the native implementation, but still faster than the iterator variant.
  7. Symfony Component Example of usage Console Manage the output of

    your command (real-time output + preserves memory) Finder Discover directories and fi les lazily (preserves I/O) HttpFoundation Streaming responses (preserves network, memory and I/O) HttpClient Responses multiplexing (async) Process Fetch running process output (realtime output + preserves memory)