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

Zero-Copy Zen: Boost Performance with Memory View

Zero-Copy Zen: Boost Performance with Memory View

Zero-copy is a technique in computer programming that allows data to be transferred between different parts of a program without being copied to intermediate buffers. In Python, this technique can be achieved using the memory view object, which provides a view into the memory of other objects. Learn how to efficiently manipulate large datasets and optimise your code with the help of this powerful tool. Whether you're working with sockets, objects or memory profiling, memory view is your key to faster and more efficient Python programming.

The deck was created for presentation at PyCon India '23, and was designed by Reon Saji.
[https://www.linkedin.com/in/reonsaji]

Kesia Joies

October 09, 2023
Tweet

Other Decks in Programming

Transcript

  1. A method to copy data from the disk/network to the

    memory without passing through the CPU
  2. Buffer Protocol It is a protocol that provides a way

    to access the internal data of an object.
  3. Buffer Protocol But the problem is, even if we cannot

    access this protocol with the standard code base, this is accessible to us at the C-API level.
  4. Buffer Protocol But the problem is, even if we cannot

    access this protocol with the standard code base, this is accessible to us at the C-API level. So, in Python, if we want to expose the same protocol in Python, we need to use memory view.
  5. Immutable data type Return a byte object Must be iterable

    of integers between 0 <= x < 256 Bytes
  6. PEP 688 – Making the buffer protocol accessible in Python

    • A better way to interact with the buffer protocol directly. • Now supports additional types with the buffer protocol. • Simplified Workflow • Performance Boost
  7. References 1. Idea of zero copy [with example] 2. Effective

    Python › Item 74: Consider memoryview and bytearray for Zero-Copy Interactions with bytes 3. Python memoryview() 4. Python Memoryview Example for Beginners 5. memoryview in Python 6. Python memoryview() Function (Buffer Protocol And Memory View) 7. PEP 688 – Making the buffer protocol accessible in Python