GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||
GeezerVison is showing github.com — gh-100239: specialize bytes binary operations by Wulian233 · Pull Request #149458 · python/cpython Conversation
|
| Benchmark | Specialized median | Unspecialized median | Speedup |
|---|---|---|---|
bytes[3] |
0.513025s |
0.701673s |
~26.9% faster |
import statistics import time N = 20_000_000 REPEAT = 7 def bench_bytes_index(): b = b"foobar" x = 0 for _ in range(N): x = b[3] return x # Warm up for specialization. for _ in range(5): bench_bytes_index() samples = [] for _ in range(REPEAT): t0 = time.perf_counter() result = bench_bytes_index() samples.append(time.perf_counter() - t0) print("result", result) print("samples", " ".join(f"{s:.6f}" for s in samples)) print("median", f"{statistics.median(samples):.6f}")
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| static PyObject * | ||
| bytes_slice_subscr(PyObject *lhs, PyObject *rhs) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The implementation here is seems copied from bytes_subscript (in byteobject.c) and still has a large overlap. Can you refactor the bytes_subscript into multiple methods so that the method here only becomes a very thin wrapper?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am not sure we actually need this specialization. Is there any metrics that that this operation is executed frequently in performance benchmark.
We can add tons of specialization it we want, but IIUC, we just pick few of them.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I agree we should limit the number of specializations. The bytes indexing seems worthwhile atm, the bytes slicing not so much. Another option: reconsider an extension mechanism. It was implemented once and reverted (because of a python release date and some technical worries): #133395. If we can get similar performance improvements with the extension mechanism, when we can leave which ops to specialize to the user and outside cpython. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Documentation build overview
26 files changed ·
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.