Avatar for the PyO3 user
PyO3
pyo3
BlogDocsChangelog

improve performance of successful int extract by ~30% by avoiding calls to `__index__` where redundant

#3742Merged
Comparing
samuelcolvin:int-extraction-performance
(
0e876d9
) with
main
(
7366b1a
)
CodSpeed Performance Gauge
+37%
Improvements
8
Regressions
0
Untouched
55
New
0
Dropped
0
Ignored
15

Benchmarks

Improved

iter_tuple
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::iter_tuple
CodSpeed Performance Gauge
+28%
6.7 ms
5.2 ms
tuple_get_item_unchecked
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::tuple_get_item_unchecked
CodSpeed Performance Gauge
+25%
3.7 ms
2.9 ms
tuple_get_item
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::tuple_get_item
CodSpeed Performance Gauge
+21%
4.2 ms
3.5 ms
iter_list
pyo3-benches/benches/bench_list.rs::benches::criterion_benchmark::iter_list
CodSpeed Performance Gauge
+20%
8.8 ms
7.3 ms
list_get_item_unchecked
pyo3-benches/benches/bench_list.rs::benches::criterion_benchmark::list_get_item_unchecked
CodSpeed Performance Gauge
+19%
4.5 ms
3.7 ms
list_get_item
pyo3-benches/benches/bench_list.rs::benches::criterion_benchmark::list_get_item
CodSpeed Performance Gauge
+17%
5 ms
4.2 ms
extract_hashmap
pyo3-benches/benches/bench_dict.rs::benches::criterion_benchmark::extract_hashmap
CodSpeed Performance Gauge
+13%
25 ms
22.1 ms
iter_dict
pyo3-benches/benches/bench_dict.rs::benches::criterion_benchmark::iter_dict
CodSpeed Performance Gauge
+11%
14.8 ms
13.4 ms

Passed

iter_set
pyo3-benches/benches/bench_set.rs::benches::criterion_benchmark::iter_set
CodSpeed Performance Gauge
+9%
17 ms
15.6 ms
extract_btreeset
pyo3-benches/benches/bench_set.rs::benches::criterion_benchmark::extract_btreeset
CodSpeed Performance Gauge
+8%
19.5 ms
18.1 ms
extract_btreemap
pyo3-benches/benches/bench_dict.rs::benches::criterion_benchmark::extract_btreemap
CodSpeed Performance Gauge
+7%
41.5 ms
38.6 ms
extract_hashset
pyo3-benches/benches/bench_set.rs::benches::criterion_benchmark::extract_hashset
CodSpeed Performance Gauge
+7%
23.5 ms
22.1 ms
dict_get_item
pyo3-benches/benches/bench_dict.rs::benches::criterion_benchmark::dict_get_item
CodSpeed Performance Gauge
+4%
17.3 ms
16.6 ms
extract_float_extract_fail
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_float_extract_fail
CodSpeed Performance Gauge
+3%
12.2 µs
11.8 µs
getattr_intern
pyo3-benches/benches/bench_intern.rs::benches::criterion_benchmark::getattr_intern
CodSpeed Performance Gauge
+2%
3.2 µs
3.1 µs
test_none_py
pytests/tests/test_pyfunctions.py::test_none_py
CodSpeed Performance Gauge
+1%
12.6 µs
12.4 µs
tuple_into_py
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::tuple_into_py
CodSpeed Performance Gauge
+1%
2.9 µs
2.9 µs
test_simple_args_rs
pytests/tests/test_pyfunctions.py::test_simple_args_rs
CodSpeed Performance Gauge
+1%
22.4 µs
22.2 µs
test_empty_class_init_py
pytests/tests/test_pyclasses.py::test_empty_class_init_py
CodSpeed Performance Gauge
+1%
16.9 µs
16.7 µs
err_new_restore_and_fetch
pyo3-benches/benches/bench_err.rs::benches::criterion_benchmark::err_new_restore_and_fetch
CodSpeed Performance Gauge
+1%
7.5 µs
7.5 µs
first_time_init
pyo3-benches/benches/bench_pyclass.rs::benches::criterion_benchmark::first_time_init
CodSpeed Performance Gauge
+1%
39.1 µs
38.8 µs
test_none_rs
pytests/tests/test_pyfunctions.py::test_none_rs
CodSpeed Performance Gauge
0%
12.8 µs
12.8 µs
extract_bigint_huge_negative
pyo3-benches/benches/bench_bigint.rs::benches::criterion_benchmark::extract_bigint_huge_negative
CodSpeed Performance Gauge
0%
13.5 µs
13.5 µs
test_simple_kwargs_rs
pytests/tests/test_pyfunctions.py::test_simple_kwargs_rs
CodSpeed Performance Gauge
0%
24.5 µs
24.5 µs
test_simple_args_py
pytests/tests/test_pyfunctions.py::test_simple_args_py
CodSpeed Performance Gauge
0%
19.1 µs
19.1 µs
test_simple_args_kwargs_rs
pytests/tests/test_pyfunctions.py::test_simple_args_kwargs_rs
CodSpeed Performance Gauge
0%
24.7 µs
24.7 µs
call_method_0
pyo3-benches/benches/bench_call.rs::benches::criterion_benchmark::call_method_0
CodSpeed Performance Gauge
0%
701.5 µs
701.4 µs
tuple_to_list
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::tuple_to_list
CodSpeed Performance Gauge
0%
1.9 ms
1.9 ms
tuple_new_list
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::tuple_new_list
CodSpeed Performance Gauge
0%
2.5 ms
2.5 ms
set_new
pyo3-benches/benches/bench_set.rs::benches::criterion_benchmark::set_new
CodSpeed Performance Gauge
0%
18.8 ms
18.8 ms
list_new
pyo3-benches/benches/bench_list.rs::benches::criterion_benchmark::list_new
CodSpeed Performance Gauge
0%
6.7 ms
6.7 ms
collect_generic_iterator
pyo3-benches/benches/bench_any.rs::benches::criterion_benchmark::collect_generic_iterator
CodSpeed Performance Gauge
0%
91.4 ms
91.4 ms
call_0
pyo3-benches/benches/bench_call.rs::benches::criterion_benchmark::call_0
CodSpeed Performance Gauge
0%
214 µs
214 µs
err_new_without_gil
pyo3-benches/benches/bench_err.rs::benches::criterion_benchmark::err_new_without_gil
CodSpeed Performance Gauge
0%
1.3 µs
1.3 µs
extract_float_downcast_fail
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_float_downcast_fail
CodSpeed Performance Gauge
0%
399.4 ns
399.4 ns
f64_from_pyobject
pyo3-benches/benches/bench_frompyobject.rs::benches::criterion_benchmark::f64_from_pyobject
CodSpeed Performance Gauge
0%
334.4 ns
334.4 ns
clean_acquire_gil
pyo3-benches/benches/bench_gil.rs::benches::criterion_benchmark::clean_acquire_gil
CodSpeed Performance Gauge
0%
3.6 µs
3.6 µs
clean_gilpool_new
pyo3-benches/benches/bench_gil.rs::benches::criterion_benchmark::clean_gilpool_new
CodSpeed Performance Gauge
0%
500.8 ns
500.8 ns
dirty_acquire_gil
pyo3-benches/benches/bench_gil.rs::benches::criterion_benchmark::dirty_acquire_gil
CodSpeed Performance Gauge
0%
4.4 µs
4.4 µs
drop_many_objects
pyo3-benches/benches/bench_pyobject.rs::benches::criterion_benchmark::drop_many_objects
CodSpeed Performance Gauge
0%
9.4 µs
9.4 µs
test_simple_py
pytests/tests/test_pyfunctions.py::test_simple_py
CodSpeed Performance Gauge
0%
19.1 µs
19.1 µs
tuple_new
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::tuple_new
CodSpeed Performance Gauge
0%
6.7 ms
6.7 ms
dict_new
pyo3-benches/benches/bench_dict.rs::benches::criterion_benchmark::dict_new
CodSpeed Performance Gauge
0%
25.3 ms
25.3 ms
test_args_kwargs_py
pytests/tests/test_pyfunctions.py::test_args_kwargs_py
CodSpeed Performance Gauge
0%
22.4 µs
22.4 µs
test_simple_args_kwargs_py
pytests/tests/test_pyfunctions.py::test_simple_args_kwargs_py
CodSpeed Performance Gauge
0%
22.7 µs
22.7 µs
test_empty_class_init
pytests/tests/test_pyclasses.py::test_empty_class_init
CodSpeed Performance Gauge
0%
22.9 µs
22.9 µs
test_simple_rs
pytests/tests/test_pyfunctions.py::test_simple_rs
CodSpeed Performance Gauge
0%
19.6 µs
19.6 µs
test_simple_kwargs_py
pytests/tests/test_pyfunctions.py::test_simple_kwargs_py
CodSpeed Performance Gauge
0%
23.2 µs
23.3 µs
not_a_list_via_extract_enum
pyo3-benches/benches/bench_frompyobject.rs::benches::criterion_benchmark::not_a_list_via_extract_enum
CodSpeed Performance Gauge
0%
13.6 µs
13.7 µs
extract_bigint_huge_positive
pyo3-benches/benches/bench_bigint.rs::benches::criterion_benchmark::extract_bigint_huge_positive
CodSpeed Performance Gauge
0%
12.2 µs
12.3 µs
test_args_kwargs_rs
pytests/tests/test_pyfunctions.py::test_args_kwargs_rs
CodSpeed Performance Gauge
-1%
16.6 µs
16.7 µs
extract_int_extract_fail
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_int_extract_fail
CodSpeed Performance Gauge
-1%
11.4 µs
11.4 µs
enum_from_pyobject
pyo3-benches/benches/bench_frompyobject.rs::benches::criterion_benchmark::enum_from_pyobject
CodSpeed Performance Gauge
-1%
19.3 µs
19.5 µs
extract_bigint_big_negative
pyo3-benches/benches/bench_bigint.rs::benches::criterion_benchmark::extract_bigint_big_negative
CodSpeed Performance Gauge
-1%
4.1 µs
4.1 µs
extract_bigint_extract_fail
pyo3-benches/benches/bench_bigint.rs::benches::criterion_benchmark::extract_bigint_extract_fail
CodSpeed Performance Gauge
-1%
11.4 µs
11.5 µs
extract_bigint_big_positive
pyo3-benches/benches/bench_bigint.rs::benches::criterion_benchmark::extract_bigint_big_positive
CodSpeed Performance Gauge
-1%
3.8 µs
3.8 µs
not_a_list_via_extract
pyo3-benches/benches/bench_frompyobject.rs::benches::criterion_benchmark::not_a_list_via_extract
CodSpeed Performance Gauge
-2%
1.8 µs
1.8 µs
decimal_via_extract
pyo3-benches/benches/bench_decimal.rs::benches::criterion_benchmark::decimal_via_extract
CodSpeed Performance Gauge
-2%
14.9 µs
15.2 µs
ordered_richcmp
pyo3-benches/benches/bench_comparisons.rs::benches::criterion_benchmark::ordered_richcmp
CodSpeed Performance Gauge
-2%
3 µs
3 µs
extract_bigint_small
pyo3-benches/benches/bench_bigint.rs::benches::criterion_benchmark::extract_bigint_small
CodSpeed Performance Gauge
-3%
3 µs
3.1 µs
identify_object_type
pyo3-benches/benches/bench_any.rs::benches::criterion_benchmark::identify_object_type
CodSpeed Performance Gauge
-3%
15.5 µs
16 µs
extract_str_extract_fail
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_str_extract_fail
CodSpeed Performance Gauge
-4%
1.9 µs
2 µs
ordered_dunder_methods
pyo3-benches/benches/bench_comparisons.rs::benches::criterion_benchmark::ordered_dunder_methods
CodSpeed Performance Gauge
-5%
2.8 µs
3 µs

Ignored

mapping_from_dictIgnored
pyo3-benches/benches/bench_dict.rs::benches::criterion_benchmark::mapping_from_dict
CodSpeed Performance Gauge
0%
364.4 ns
364.4 ns
extract_float_downcast_successIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_float_downcast_success
CodSpeed Performance Gauge
0%
398.1 ns
398.1 ns
extract_float_extract_successIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_float_extract_success
CodSpeed Performance Gauge
0%
396.4 ns
396.4 ns
extract_int_downcast_failIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_int_downcast_fail
CodSpeed Performance Gauge
+16%
216.1 ns
186.9 ns
extract_int_downcast_successIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_int_downcast_success
CodSpeed Performance Gauge
+37%
714.7 ns
523.1 ns
extract_int_extract_successIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_int_extract_success
CodSpeed Performance Gauge
+37%
713.3 ns
521.7 ns
extract_str_downcast_failIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_str_downcast_fail
CodSpeed Performance Gauge
0%
216.1 ns
216.1 ns
extract_str_downcast_successIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_str_downcast_success
CodSpeed Performance Gauge
-5%
525 ns
554.2 ns
extract_str_extract_successIgnored
pyo3-benches/benches/bench_extract.rs::benches::criterion_benchmark::extract_str_extract_success
CodSpeed Performance Gauge
-14%
525 ns
612.5 ns
list_via_downcastIgnored
pyo3-benches/benches/bench_frompyobject.rs::benches::criterion_benchmark::list_via_downcast
CodSpeed Performance Gauge
0%
148.3 ns
148.3 ns
list_via_extractIgnored
pyo3-benches/benches/bench_frompyobject.rs::benches::criterion_benchmark::list_via_extract
CodSpeed Performance Gauge
0%
271.4 ns
271.4 ns
not_a_list_via_downcastIgnored
pyo3-benches/benches/bench_frompyobject.rs::benches::criterion_benchmark::not_a_list_via_downcast
CodSpeed Performance Gauge
-20%
119.2 ns
148.3 ns
getattr_directIgnored
pyo3-benches/benches/bench_intern.rs::benches::criterion_benchmark::getattr_direct
CodSpeed Performance Gauge
+1%
6.8 µs
6.8 µs
sequence_from_listIgnored
pyo3-benches/benches/bench_list.rs::benches::criterion_benchmark::sequence_from_list
CodSpeed Performance Gauge
0%
306.4 ns
306.4 ns
sequence_from_tupleIgnored
pyo3-benches/benches/bench_tuple.rs::benches::criterion_benchmark::sequence_from_tuple
CodSpeed Performance Gauge
0%
306.9 ns
306.9 ns

Commits

Click on a commit to change the comparison range
Base
main
7366b1a
+37%
improve performance of successful int extract by ~30% add newsfragment formatting skip slow path on 3.8+ formatting cfg if,else formatting again dedicated macro, change int_convert_u64_or_i64 too add float tests force index call for PyLong_AsUnsignedLongLong perform PyLong check for 3.8 too perform PyLong check for <3.10
0e876d9
1 year ago
by samuelcolvin
Home Terms PrivacyDocs