-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix quadratic time ByteBuffer operations #711
Conversation
Cool! Are you able to run any benchmarks? |
$ python benchmark/bytebuffer_bench.py
0.0012826919555664062
$ git stash; git checkout HEAD^; git stash pop
$ python benchmark/bytebuffer_bench.py
0.13568520545959473 Benchmark is import time
from smart_open.bytebuffer import ByteBuffer
buffer = ByteBuffer()
start = time.time()
for _ in range(1000):
assert buffer.fill([b"X" * 1000]) == 1000
print(time.time() - start) In terms of production code, I found this is a significant speedup for large unpickles. |
A benchmark on some real |
$ python benchmark/bytebuffer_bench.py "$BENCHMARK_FILE"
Raw ByteBuffer benchmark: 0.012549877166748047
File read benchmark 1.083221435546875
$ git revert 8cc7654580b207dc7a684fab856ef1a708b106b1
[develop a5fc7a7] Revert "Fix quadratic time ByteBuffer operations"
$ python benchmark/bytebuffer_bench.py "$BENCHMARK_FILE"
Raw ByteBuffer benchmark: 21.479155778884888
File read benchmark 25.684982776641846
|
Merged! Thank you. |
Would it be possible to get a release containing this fix so it's easier for us to upgrade? Thanks in advance! |
Thank you! |
bytes
is immutable, so repeated appends is quadratic-time.bytearray
is the mutable version ofbytes
.