Skip to content

bpo-38938: Reduce the number of comparisons in heapq.merge - #18427

Closed
sweeneyde wants to merge 6 commits into
python:masterfrom
sweeneyde:heapq-merge
Closed

sweeneyde wants to merge 6 commits into
python:masterfrom
sweeneyde:heapq-merge

Conversation

@sweeneyde

@sweeneyde sweeneyde commented Feb 10, 2020 •

Copy link
Copy Markdown
Member

I accidentally polluted the previous PR (#17729) with recent commits to unrelated files, but I think this might still be a viable speed boost--the code should be the same.

This is essentially a lazy non-recursive recursive-merge-sort, which turns out to be exactly equivalent to repeated heapreplace calls, with one exception: it eliminates the siftdown at the end of each siftup call, which is unnecessary because the inputs are already sorted. This modestly improves performance in almost all cases, and especially improves performance when one iterator keeps "winning."

https://bugs.python.org/issue38938

@codecov

codecov Bot commented Feb 10, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #18427 into master will increase coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #18427     +/-   ##
=========================================
  Coverage   82.11%   82.12%             
=========================================
  Files        1955     1954      -1     
  Lines      588948   583956   -4992     
  Branches    44428    44447     +19     
=========================================
- Hits       483629   479561   -4068     
+ Misses      95669    94749    -920     
+ Partials     9650     9646      -4     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) ⬇️
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) ⬇️
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) ⬇️
Lib/test/test_smtpnet.py 78.57% <0.00%> (-7.15%) ⬇️
Lib/ftplib.py 63.85% <0.00%> (-6.06%) ⬇️
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) ⬇️
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) ⬇️
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) ⬇️
Lib/test/test_socket.py 71.94% <0.00%> (-3.77%) ⬇️
Lib/test/test_asyncio/test_base_events.py 91.84% <0.00%> (-3.30%) ⬇️
... and 322 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6dedde...1077614. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants