Skip to content

feat(bindings/python): read APIs return memoryview instead of bytes to avoid copy#3310

Merged
Xuanwo merged 1 commit intoapache:mainfrom
messense:python-memoryview
Oct 16, 2023
Merged

feat(bindings/python): read APIs return memoryview instead of bytes to avoid copy#3310
Xuanwo merged 1 commit intoapache:mainfrom
messense:python-memoryview

Conversation

@messense
Copy link
Copy Markdown
Member

Before

In [1]: import opendal

In [2]: op = opendal.Operator("memory")

In [3]: op.write("test", bytes(10 * 1024 * 1024))

In [4]: %timeit op.read("test")
627 µs ± 3.9 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

After

In [1]: import opendal

In [2]: op = opendal.Operator("memory")

In [3]: op.write("test", bytes(10 * 1024 * 1024))

In [4]: %timeit op.read("test")
291 µs ± 761 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

Unfortunately better performance comes with a price, we're no longer able to build abi3 wheels which means we need to build and publish one wheel per Python version, OS and CPU architecture.

We can remove the unsafe once PyO3/pyo3#3514 is released.

@github-actions github-actions Bot added the releases-note/feat The PR implements a new feature or has a title that begins with "feat" label Oct 16, 2023
@messense messense force-pushed the python-memoryview branch 2 times, most recently from a980a68 to 963122c Compare October 16, 2023 13:13
…s` to avoid copy

Before

```python
In [1]: import opendal

In [2]: op = opendal.Operator("memory")

In [3]: op.write("test", bytes(10 * 1024 * 1024))

In [4]: %timeit op.read("test")
627 µs ± 3.9 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
```

After

```python
In [1]: import opendal

In [2]: op = opendal.Operator("memory")

In [3]: op.write("test", bytes(10 * 1024 * 1024))

In [4]: %timeit op.read("test")
291 µs ± 761 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
```
@messense messense marked this pull request as ready for review October 16, 2023 13:20
Comment thread bindings/python/Cargo.toml
Copy link
Copy Markdown
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bindings/python releases-note/feat The PR implements a new feature or has a title that begins with "feat"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants