perf: use new PyLong* API for num-bigint feature#6144
Conversation
Merging this PR will improve performance by 68.84%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | into_bigint_huge_negative |
23.6 µs | 6.6 µs | ×3.6 |
| ⚡ | extract_biguint_negative_fail |
7.2 µs | 2.3 µs | ×3.2 |
| ⚡ | extract_biguint_zero |
2,758.9 ns | 946.1 ns | ×2.9 |
| ⚡ | into_bigint_huge_positive |
17.4 µs | 6.7 µs | ×2.6 |
| ⚡ | into_biguint_huge |
17.1 µs | 6.7 µs | ×2.6 |
| ⚡ | into_bigint_big_negative |
5.3 µs | 2.1 µs | ×2.5 |
| ⚡ | into_bigint_small |
3.2 µs | 1.5 µs | ×2.1 |
| ⚡ | into_bigint_big_positive |
4.5 µs | 2.1 µs | ×2.1 |
| ⚡ | into_biguint_big |
4.3 µs | 2.2 µs | +96.34% |
| ⚡ | into_biguint_small |
3.3 µs | 2 µs | +68.45% |
| ⚡ | extract_bigint_small |
2.7 µs | 1.8 µs | +53.52% |
| ⚡ | extract_bigint_huge_negative |
13 µs | 8.5 µs | +52.37% |
| ⚡ | extract_biguint_small |
2.6 µs | 1.7 µs | +50.52% |
| ⚡ | into_biguint_zero |
2.9 µs | 2 µs | +41.44% |
| ⚡ | extract_biguint_huge |
11.8 µs | 8.5 µs | +37.87% |
| ⚡ | extract_bigint_huge_positive |
11.7 µs | 8.5 µs | +37.36% |
| ⚡ | extract_bigint_big_negative |
3.9 µs | 3.4 µs | +14.46% |
| ⚡ | extract_i128_small_pos |
1.2 µs | 1.1 µs | +14.18% |
| ⚡ | extract_i128_zero |
1.3 µs | 1.1 µs | +13.81% |
| ⚡ | extract_i128_small_neg |
1.3 µs | 1.2 µs | +13.06% |
| ... | ... | ... | ... | ... |
ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing chirizxc:PyLongForBigInt (b1899b6) with main (126aa44)
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks, generally looks good on the from-python implementation; I think possible gains yet to be had in the to-python implementation.
|
|
||
| #[cfg(all(not(Py_LIMITED_API), Py_3_14))] | ||
| { | ||
| if is_30bit_layout() { |
There was a problem hiding this comment.
Some observations on this path:
- I would prefer to have this logic extracted into a generic function; I think it's easier to maintain than when it's deeply nested inside a macro.
- I think we can avoid the intermediate
Vecallocation from the digits and instead wrap the iterator coming out of the big-integer.pylong_from_digitsneeds anExactSizeIterator, so it'll be a touch fiddly but I think still possible. - I think we lack benchmarks for the bigint to-python pathway, so possibly worth landing some of those before we think too hard about this.
There was a problem hiding this comment.
- I think we lack benchmarks for the bigint to-python pathway, so possibly worth landing some of those before we think too hard about this.
|
Also, I think worth giving this a |
PyLong API for num-bigint featurePyLong* API for num-bigint feature
Related: #6040
See codspeed comment for benchmark improvements.