Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use list comprehensions to avoid append() calls #1254

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

correctmost
Copy link
Contributor

This provides a small speed-up on large codebases (~80ms).

Stats

Before

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 12900025    2.590    0.000    2.590    0.000 {method 'append' of 'list' objects}
Command Mean [s] Min [s] Max [s] Relative
pycodestyle . 18.178 ± 0.198 17.951 18.666 1.00

After

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  4457822    1.049    0.000    1.049    0.000 {method 'append' of 'list' objects}
Command Mean [s] Min [s] Max [s] Relative
pycodestyle . 18.099 ± 0.132 17.887 18.346 1.00

Set-up

I profiled pycodestyle with the yt-dlp codebase because it is similar in composition to a private codebase I have.

git clone https://github.com/yt-dlp/yt-dlp.git
cd yt-dlp

git checkout ef36d517f9b05785d61abca7691d9ab7d63cc75c

# Callgraph command
python -m cProfile -o stats $(which pycodestyle)

# Benchmarking command
hyperfine --ignore-failure --warmup 2 --runs 10 --export-markdown=baseline.md 'pycodestyle .'

setup.cfg

[pycodestyle]
ignore = W504
max-line-length = 100

This provides a small speed-up on large codebases.
Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asottile asottile merged commit fc2c2ba into PyCQA:main Aug 9, 2024
9 checks passed
@correctmost correctmost deleted the cm/avoid-appends branch August 9, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants