Skip to content

Conversation

methane
Copy link
Member

@methane methane commented May 19, 2016

bytearray may be best option for buffer.
But PyPy's struct.unpack is slower on bytearray.
So we use bytes for now.

@jfolz
Copy link
Contributor

jfolz commented May 19, 2016

Seems like PyPy doesn't like it:

unpacking integers (fallback)    0.211348, 0.154564, 0.154378, 0.156010
unpacking bytes (fallback)       0.563791, 0.541599, 0.537913, 0.541811
unpacking lists (fallback)       0.393923, 0.392007, 0.379326, 0.384622
unpacking dicts (fallback)       0.351910, 0.347979, 0.348440, 0.350482

0.4.7:

unpacking integers (fallback)    0.133905, 0.067842, 0.066790, 0.067156
unpacking bytes (fallback)       0.104518, 0.074977, 0.074882, 0.074800
unpacking lists (fallback)       0.310753, 0.299883, 0.295808, 0.298838
unpacking dicts (fallback)       0.283737, 0.262611, 0.276033, 0.262426

@methane
Copy link
Member Author

methane commented May 19, 2016

bytearray on PyPy is slower than bytes.

master:

unpacking integers (fallback)    0.174160, 0.118780, 0.094318, 0.092160
unpacking bytes (fallback)       0.154044, 0.085751, 0.079935, 0.084918
unpacking lists (fallback)       1.458416, 1.300095, 1.300537, 1.306590
unpacking dicts (fallback)       1.170090, 0.995266, 0.996789, 0.991890

bytearray (5c47807):

unpacking integers (fallback)    0.146611, 0.111243, 0.089572, 0.089555
unpacking bytes (fallback)       0.131598, 0.079429, 0.077857, 0.081479
unpacking lists (fallback)       1.345462, 1.204245, 1.210770, 1.205473
unpacking dicts (fallback)       1.028819, 0.927366, 0.927691, 0.929977

@methane
Copy link
Member Author

methane commented May 20, 2016

FYI, I've filed an issue of bytearray inefficiency to PyPy.
https://bitbucket.org/pypy/pypy/issues/2303/structunpack-is-15x-slower-on-bytearray

@methane methane changed the title fallback: Rewrite buffer from array of bytes to bytearray fallback: Rewrite buffer from array of bytes to bytes May 20, 2016
@methane
Copy link
Member Author

methane commented May 20, 2016

@jfolz Are you OK to this change?

@jfolz
Copy link
Contributor

jfolz commented May 20, 2016

@methane Frankly the old buffer code is a mystery to me. This looks much cleaner.

@methane
Copy link
Member Author

methane commented May 21, 2016

On discussion in PyPy issue, Armin pointed out that microbenchmarking on PyPy is too optimized
since we use same bytes for each run.
We need more good benchmark...

@jfolz
Copy link
Contributor

jfolz commented May 21, 2016

What I gather from that thread is that:

  1. Data needs to be different for every run (+ possibly random)
  2. Results must be properly used in some way

Though, exactly what "properly used" means is unclear.

@methane
Copy link
Member Author

methane commented May 22, 2016

I've tried another benchmark in my local and I think performance difference between bytes and bytearray is significant.

patch and bench

I merge this pull request as is, and I'll discuss about "slice and unpack" performance in other place.

@methane methane merged commit ae8e98e into msgpack:master May 22, 2016
@methane methane deleted the fallback-bytearray-buffer branch May 22, 2016 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants