Nick Pope
b47f2f5b90
Fixed #33865 -- Optimized LimitedStream wrapper.
...
The current implementation of LimitedStream is slow because .read()
performs an extra copy into a buffer and .readline() performs two
extra copies. The stream being wrapped is already typically a BytesIO
object so this is unnecessary.
This implementation has largely been untouched for 12 years and,
inspired by a simpler implementation in werkzeug, it was possible to
achieve the following performance improvement:
LimitedStream.read() (single line):
Mean +- std dev: [bench_limitedstream-main] 286 ns +- 6 ns
-> [bench_limitedstream-patch] 227 ns +- 6 ns: 1.26x faster
LimitedStream.readline() (single line):
Mean +- std dev: [bench_limitedstream-main] 507 ns +- 11 ns
-> [bench_limitedstream-patch] 232 ns +- 8 ns: 2.18x faster
LimitedStream.read(8192) (single line):
Mean +- std dev: [bench_limitedstream-main] 360 ns +- 8 ns
-> [bench_limitedstream-patch] 297 ns +- 6 ns: 1.21x faster
LimitedStream.readline(8192) (single line):
Mean +- std dev: [bench_limitedstream-main] 602 ns +- 10 ns
-> [bench_limitedstream-patch] 305 ns +- 10 ns: 1.98x faster
LimitedStream.read() (multiple lines):
Mean +- std dev: [bench_limitedstream-main] 290 ns +- 5 ns
-> [bench_limitedstream-patch] 236 ns +- 6 ns: 1.23x faster
LimitedStream.readline() (multiple lines):
Mean +- std dev: [bench_limitedstream-main] 517 ns +- 19 ns
-> [bench_limitedstream-patch] 239 ns +- 7 ns: 2.16x faster
LimitedStream.read(8192) (multiple lines):
Mean +- std dev: [bench_limitedstream-main] 363 ns +- 8 ns
-> [bench_limitedstream-patch] 311 ns +- 11 ns: 1.17x faster
LimitedStream.readline(8192) (multiple lines):
Mean +- std dev: [bench_limitedstream-main] 601 ns +- 12 ns
-> [bench_limitedstream-patch] 308 ns +- 7 ns: 1.95x faster
Geometric mean: 1.59x faster
2023-01-05 19:26:56 +01:00
..
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-10-06 20:44:07 +02:00
2022-04-25 11:00:50 +02:00
2022-06-22 07:50:24 +02:00
2022-02-07 20:37:05 +01:00
2022-12-28 12:31:04 +01:00
2022-04-18 07:05:52 +02:00
2022-10-31 12:30:13 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-10-20 13:38:31 -07:00
2022-10-07 13:05:35 +02:00
2022-12-06 11:14:32 +01:00
2022-10-27 08:41:03 +02:00
2022-12-21 11:41:29 +01:00
2022-11-07 12:21:29 +01:00
2022-11-07 20:23:53 +01:00
2022-02-07 20:37:05 +01:00
2022-03-08 14:50:06 +01:00
2022-12-22 10:41:12 +01:00
2022-12-20 11:10:48 +01:00
2023-01-04 09:11:36 +01:00
2023-01-03 09:30:53 +01:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2023-01-05 19:26:56 +01:00
2022-11-22 14:47:21 +01:00
2023-01-04 09:11:36 +01:00
2022-10-03 10:52:21 +02:00
2022-11-10 13:52:17 +01:00
2022-09-13 12:48:31 +02:00
2022-11-07 08:06:30 +01:00
2022-02-07 20:37:05 +01:00
2022-03-09 14:50:52 +01:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2022-03-24 06:29:50 +01:00
2022-10-07 13:05:35 +02:00
2022-10-07 13:05:35 +02:00
2022-12-15 06:17:57 +01:00
2022-02-07 20:37:05 +01:00
2022-12-15 06:17:57 +01:00
2022-07-18 06:30:20 +02:00
2022-05-25 10:58:48 +02:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-12-30 12:22:30 +01:00
2022-08-27 14:25:55 +02:00
2022-12-20 11:10:48 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-10-31 09:55:51 +01:00
2022-10-08 08:07:38 +02:00
2022-11-11 08:46:08 +01:00
2022-10-08 08:07:38 +02:00
2022-02-16 21:09:24 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-11-11 06:59:33 +01:00
2022-12-30 13:28:47 +01:00
2022-10-24 13:54:51 +02:00
2022-10-08 08:07:38 +02:00
2022-12-15 06:17:57 +01:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2022-11-28 09:47:52 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-11-09 10:32:40 +01:00
2022-11-18 10:13:31 +01:00
2022-10-08 08:07:38 +02:00
2022-06-14 12:24:43 +02:00
2022-02-07 20:37:05 +01:00
2022-10-29 13:27:10 +02:00
2023-01-03 05:47:44 +01:00
2022-12-05 10:46:33 +01:00
2022-12-22 10:41:12 +01:00
2023-01-04 11:14:06 +01:00
2023-01-04 11:47:14 +01:00
2022-07-12 09:04:31 +02:00
2022-02-07 20:37:05 +01:00
2022-12-28 12:31:04 +01:00
2022-12-28 06:28:07 +01:00
2022-12-28 12:31:04 +01:00
2022-12-27 06:39:38 +01:00
2023-01-04 09:11:36 +01:00
2022-12-21 11:41:29 +01:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-04-14 12:12:13 +02:00
2022-09-30 18:18:33 +02:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-11-10 13:52:17 +01:00
2022-02-07 20:37:05 +01:00
2022-09-30 18:18:33 +02:00
2022-10-08 08:07:38 +02:00
2022-02-22 09:16:40 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2023-01-04 09:11:36 +01:00
2022-12-20 11:10:48 +01:00
2022-09-27 21:10:30 +02:00
2022-02-07 20:37:05 +01:00
2022-12-28 06:28:07 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-12-30 13:28:47 +01:00
2022-08-08 09:46:05 +02:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-06-13 07:21:46 +02:00
2022-11-02 12:30:16 +01:00
2022-10-08 08:07:38 +02:00
2022-02-07 20:37:05 +01:00
2022-07-26 11:41:19 +02:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2022-02-07 20:37:05 +01:00
2022-04-15 07:46:37 +02:00
2022-10-08 08:07:38 +02:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2022-02-07 20:37:05 +01:00
2022-02-22 09:16:40 +01:00
2022-02-22 10:29:38 +01:00
2022-10-08 08:07:38 +02:00
2022-10-08 08:07:38 +02:00
2022-10-18 17:31:45 -07:00
2022-10-13 12:27:41 +02:00
2022-12-28 12:31:04 +01:00
2022-12-21 11:41:29 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-02-22 10:29:38 +01:00
2022-07-04 06:37:36 +02:00
2022-12-21 11:41:29 +01:00
2022-02-07 20:37:05 +01:00
2022-04-18 07:05:52 +02:00
2022-02-07 20:37:05 +01:00
2023-01-05 19:25:25 +01:00
2023-01-05 18:09:33 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-08-03 08:46:31 +02:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2022-12-28 06:28:07 +01:00
2022-12-21 11:41:29 +01:00
2022-02-22 10:29:38 +01:00
2022-02-07 20:37:05 +01:00
2022-02-22 10:29:38 +01:00
2022-09-05 20:23:32 +02:00
2022-11-24 10:52:48 +01:00
2022-11-24 15:46:41 +01:00
2022-03-23 19:33:36 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-10-08 08:07:38 +02:00
2022-03-07 07:57:14 +01:00
2022-12-09 12:44:48 +01:00
2022-12-19 12:51:52 +01:00
2022-02-22 10:29:38 +01:00
2022-02-07 20:37:05 +01:00
2023-01-02 09:53:52 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-02-07 20:37:05 +01:00
2022-05-26 10:39:51 +02:00
2022-04-19 12:13:27 +02:00
2022-02-07 20:37:05 +01:00
2023-01-04 11:14:06 +01:00
2023-01-05 19:25:25 +01:00
2023-01-04 09:11:36 +01:00
2022-02-07 20:37:05 +01:00
2022-10-31 12:31:13 +01:00
2022-02-07 20:37:05 +01:00
2022-11-24 19:41:08 +01:00
2022-10-08 08:07:38 +02:00
2022-09-06 12:21:36 +02:00
2022-12-05 10:46:33 +01:00
2022-02-07 20:37:05 +01:00
2022-10-31 09:55:51 +01:00
2022-02-07 20:37:05 +01:00
2022-03-29 10:27:40 +02:00
2022-09-01 21:09:16 +02:00
2022-06-20 17:34:52 +02:00
2023-01-05 16:38:19 +01:00
2022-05-10 11:22:23 +02:00
2022-09-17 10:02:55 +02:00
2022-02-07 20:37:05 +01:00
2023-01-04 09:11:36 +01:00
2022-02-07 20:37:05 +01:00
2022-03-04 12:55:37 +01:00
2022-08-03 11:42:51 +02:00
2022-02-07 20:37:05 +01:00