Repository navigation
Add return const instruction #101632
Copy link
Copy link
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
Description
Activity
Execution counts for all instructions in the main branch
Name Count Self Cumulative Miss ratio LOAD_CONST 4,447,532,233 4.7% 24.4% RETURN_VALUE 3,241,585,933 3.4% 43.2% And execution counts for all instructions in my branch
Name Count Self Cumulative Miss ratio LOAD_CONST 3,477,437,602 3.7% 31.5% RETURN_VALUE 2,268,077,678 2.4% 47.3% RETURN_CONST 967,592,289 1.0% 69.3% I have executed pyperformance on my server, compare to commit d3e2dd6
python3 -m pyperf compare_to --table --min-speed 5 /python-3.12.0/results.json results.json +---------------------+---------------------------------------+-----------------------+ | Benchmark | python-3.12.0/results.json | results.json | +=====================+=======================================+=======================+ | coverage | 378 ms | 360 ms: 1.05x faster | +---------------------+---------------------------------------+-----------------------+ | crypto_pyaes | 87.2 ms | 82.5 ms: 1.06x faster | +---------------------+---------------------------------------+-----------------------+ | logging_silent | 108 ns | 94.3 ns: 1.15x faster | +---------------------+---------------------------------------+-----------------------+ | pickle_pure_python | 352 us | 330 us: 1.07x faster | +---------------------+---------------------------------------+-----------------------+ | regex_v8 | 26.8 ms | 23.8 ms: 1.12x faster | +---------------------+---------------------------------------+-----------------------+ | richards | 54.6 ms | 51.7 ms: 1.06x faster | +---------------------+---------------------------------------+-----------------------+ | scimark_lu | 125 ms | 133 ms: 1.07x slower | +---------------------+---------------------------------------+-----------------------+ | scimark_monte_carlo | 83.3 ms | 74.3 ms: 1.12x faster | +---------------------+---------------------------------------+-----------------------+ | spectral_norm | 118 ms | 112 ms: 1.06x faster | +---------------------+---------------------------------------+-----------------------+ | sqlglot_parse | 1.71 ms | 1.61 ms: 1.06x faster | +---------------------+---------------------------------------+-----------------------+ | sqlglot_transpile | 2.00 ms | 1.89 ms: 1.06x faster | +---------------------+---------------------------------------+-----------------------+ | unpickle_list | 4.73 us | 5.06 us: 1.07x slower | +---------------------+---------------------------------------+-----------------------+ | Geometric mean | (ref) | 1.01x faster | +---------------------+---------------------------------------+-----------------------+ Benchmark hidden because not significant (68): 2to3, async_generators, async_tree_none, async_tree_cpu_io_mixed, async_tree_io, async_tree_memoization, chameleon, chaos, bench_mp_pool, bench_thread_pool, coroutines, deepcopy, deepcopy_reduce, deepcopy_memo, deltablue, django_template, docutils, dulwich_log, fannkuch, float, generators, genshi_text, genshi_xml, go, hexiom, html5lib, json_dumps, json_loads, logging_format, logging_simple, mako, mdp, meteor_contest, nbody, nqueens, pathlib, pickle, pickle_dict, pickle_list, pidigits, pprint_safe_repr, pprint_pformat, pyflate, python_startup, python_startup_no_site, raytrace, regex_compile, regex_dna, regex_effbot, scimark_fft, scimark_sor, scimark_sparse_mat_mult, sqlglot_optimize, sqlglot_normalize, sqlite_synth, sympy_expand, sympy_integrate, sympy_sum, sympy_str, telco, tornado_http, unpack_sequence, unpickle, unpickle_pure_python, xml_etree_parse, xml_etree_iterparse, xml_etree_generate, xml_etree_processAlthough the performance gain may not be high, the side effects are minimal and should be a positive optimization.
Reacted by Frank Dana- addedperformancePerformance or resource usagePerformance or resource usageinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Feb 7, 2023 - added a commit that references this issue
on Feb 7, 2023
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
From the pystats doc (pystats-2023-02-05-python-5a2b984.md), I find that
LOAD_CONST + RETURN_VALUEis a very high frequency (Because the default return of the function is None).Successors for LOAD_CONST
And predecessors for RETURN_VALUE
This means that if we add a
RETURN_CONST, we can reduce theRETURN_VALUEinstruction by 30% and theLOAD_CONSTinstruction by 20%.From the microbenchmark that there is indeed a ~10% improvement (considering the interference of function calls, I think 10% should be there), which is not very high, but it should be an optimization without adverse effects.
Linked PRs