{{ message }}
bpo-47009: Streamline list.append for the common case#31864
Merged
markshannon merged 4 commits intoApr 1, 2022
Merged
Conversation
Member
Author
|
Benchmarks are good: from pyperf import Runner, perf_counter
def bench_listcomp(loops, length):
src = list(map(float, range(length)))
t0 = perf_counter()
for i in range(loops):
[x for x in src]
return perf_counter() - t0
def bench_append(loops, length):
src = list(map(float, range(length)))
t0 = perf_counter()
for i in range(loops):
arr = []
for x in src:
arr.append(x)
return perf_counter() - t0
runner = Runner()
for n in [100, 1_000, 10_000, 100_000]:
runner.bench_time_func(f"listcomp {n}", bench_listcomp, n)
runner.bench_time_func(f"append {n}", bench_append, n)Results from GCC on WSL with |
Sorry, something went wrong.
markshannon
reviewed
Mar 18, 2022
markshannon
left a comment
Member
There was a problem hiding this comment.
I think this would be simpler, and just as fast, by renaming app1 to _PyList_AppendTakeRef (with appropriate refcount adjustments).
No need for the inline functions.
Sorry, something went wrong.
Member
Author
|
@markshannon Since pyperformance results were negligible and this has a significant speedup on operations that live in hot loops (albeit not in pyperformance), is it okay if I merge this? |
Sorry, something went wrong.
Member
|
Sorry, this dropped off my radar. |
Sorry, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.
https://bugs.python.org/issue47009