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

PI: Remove b_ call in FloatObject.write_to_stream #1044

Merged
merged 2 commits into from Jun 30, 2022
Merged

PI: Remove b_ call in FloatObject.write_to_stream #1044

merged 2 commits into from Jun 30, 2022

Conversation

MartinThoma
Copy link
Member

No description provided.

@martin-thoma
Copy link

I had one particularly nasty PDF document where compression was pretty time-consuming:

from PyPDF2 import PdfReader, PdfWriter

reader = PdfReader("example.pdf")
writer = PdfWriter()

for page in reader.pages:
    page.compress_content_streams()
    writer.add_page(page)

with open("out.pdf", "wb") as fp:
    writer.write(fp)

Before FloatObject.write_to_stream had 1.3 Million calls to b_:

image

After:

image

Graphs created via:

python -m cProfile -o profile.pstats example.py
gprof2dot -f pstats profile.pstats | dot -Tsvg -o mine.svg

@codecov
Copy link

codecov bot commented Jun 30, 2022

Codecov Report

Merging #1044 (574b334) into main (84c3e33) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1044   +/-   ##
=======================================
  Coverage   89.93%   89.93%           
=======================================
  Files          24       24           
  Lines        4479     4479           
  Branches      916      916           
=======================================
  Hits         4028     4028           
  Misses        308      308           
  Partials      143      143           
Impacted Files Coverage Δ
PyPDF2/_writer.py 88.83% <100.00%> (ø)
PyPDF2/generic.py 91.34% <100.00%> (ø)

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 84c3e33...574b334. Read the comment docs.

@MartinThoma MartinThoma merged commit f1281b9 into main Jun 30, 2022
@MartinThoma MartinThoma deleted the kill-b branch June 30, 2022 06:11
MartinThoma added a commit that referenced this pull request Jun 30, 2022
New Features (ENH):
-  Add writer.pdf_header property (getter and setter) (#1038)

Performance Improvements (PI):
-  Remove b_ call in FloatObject.write_to_stream (#1044)
-  Check duplicate objects in writer._sweep_indirect_references (#207)

Documentation (DOC):
-  How to surppress exceptions/warnings/log messages (#1037)
-  Remove hyphen from lossless (#1041)
-  Compression of content streams (#1040)
-  Fix inconsistent variable names in add-watermark.md (#1039)
-  File size reduction
-  Add CHANGELOG to the rendered docs (#1023)

Maintenance (MAINT):
-  Handle XML error when reading XmpInformation (#1030)
-  Deduplicate Code / add mutmut config (#1022)

Code Style (STY):
-  Use unnecessary one-line function / class attribute (#1043)
-  Docstring formatting (#1033)

Full Changelog: 2.4.0...2.4.1
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.

None yet

2 participants