From 5cb09b0c8a655a2a893593579a02ddb0919879e6 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Thu, 25 Feb 2021 09:00:22 +0100 Subject: [PATCH 1/2] Use io.DEFAULT_BUFFER_SIZE instead of arbitrary number in gzip module This improves the performance slightly, while also using a constant that is shared across the python code base. --- Lib/gzip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/gzip.py b/Lib/gzip.py index e422773b3edfb7..ba7b7ee140a53f 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -596,7 +596,7 @@ def main(): f = builtins.open(arg, "rb") g = open(arg + ".gz", "wb") while True: - chunk = f.read(1024) + chunk = f.read(io.DEFAULT_BUFFER_SIZE) if not chunk: break g.write(chunk) From ebeacbfbed9322e62fb36feaac00daff309f0229 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Thu, 25 Feb 2021 09:09:05 +0100 Subject: [PATCH 2/2] Add news entry --- .../next/Library/2021-02-25-09-08-55.bpo-43317.qrOOpB.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-02-25-09-08-55.bpo-43317.qrOOpB.rst diff --git a/Misc/NEWS.d/next/Library/2021-02-25-09-08-55.bpo-43317.qrOOpB.rst b/Misc/NEWS.d/next/Library/2021-02-25-09-08-55.bpo-43317.qrOOpB.rst new file mode 100644 index 00000000000000..01ff48ad90d6b6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-02-25-09-08-55.bpo-43317.qrOOpB.rst @@ -0,0 +1,3 @@ +Set the chunk size for the ``gzip`` module main function to +io.DEFAULT_BUFFER_SIZE. This is slightly faster than the 1024 bytes constant +that was used previously.