turbopipe 1.2.2__cp310-cp310-macosx_10_9_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of turbopipe might be problematic. Click here for more details.

turbopipe/__init__.py ADDED
@@ -0,0 +1,47 @@
1
+ from typing import Optional, Union
2
+
3
+ from moderngl import Buffer
4
+
5
+ from turbopipe import _turbopipe
6
+
7
+
8
+ def pipe(buffer: Union[Buffer, memoryview], fileno: int) -> None:
9
+ """
10
+ Pipe the content of a moderngl.Buffer or memoryview to a file descriptor, fast, threaded and
11
+ blocking when needed. Call `sync(buffer)` before this, and `sync()` when done for
12
+
13
+ Usage:
14
+ ```python
15
+ # Assuming `buffer = ctx.buffer(...)`
16
+ # Note: Use as `fbo.read_into(buffer)`
17
+
18
+ # As a open() file
19
+ with open("file.bin", "wb") as file:
20
+ turbopipe.pipe(buffer, file)
21
+
22
+ # As a subprocess
23
+ child = subprocess.Popen(..., stdin=subprocess.PIPE)
24
+ turbopipe.pipe(buffer, child.stdin.fileno())
25
+ ```
26
+ """
27
+ if isinstance(buffer, Buffer):
28
+ buffer = memoryview(buffer.mglo)
29
+ _turbopipe.pipe(buffer, fileno)
30
+ del buffer
31
+
32
+ def sync(buffer: Optional[Union[Buffer, memoryview]]=None) -> None:
33
+ """Waits for any pending write operation on a buffer, or 'all buffers' if None, to finish"""
34
+ if isinstance(buffer, Buffer):
35
+ buffer = memoryview(buffer.mglo)
36
+ _turbopipe.sync(buffer)
37
+ del buffer
38
+
39
+ def close() -> None:
40
+ """Syncs and deletes objects"""
41
+ _turbopipe.close()
42
+
43
+ __all__ = [
44
+ "pipe",
45
+ "sync",
46
+ "close"
47
+ ]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Gabriel Tremeschin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,374 @@
1
+ Metadata-Version: 2.1
2
+ Name: turbopipe
3
+ Version: 1.2.2
4
+ Summary: 🌀 Faster ModernGL Buffers inter-process data transfers for subprocesses
5
+ Author-Email: Tremeschin <29046864+Tremeschin@users.noreply.github.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Gabriel Tremeschin
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: issues, https://github.com/BrokenSource/TurboPipe/issues
29
+ Project-URL: repository, https://github.com/BrokenSource/TurboPipe
30
+ Project-URL: documentation, https://github.com/BrokenSource/TurboPipe
31
+ Project-URL: homepage, https://brokensrc.dev
32
+ Requires-Python: >=3.7
33
+ Requires-Dist: moderngl
34
+ Description-Content-Type: text/markdown
35
+
36
+ > [!IMPORTANT]
37
+ > <sub>Also check out [**ShaderFlow**](https://github.com/BrokenSource/ShaderFlow), where **TurboPipe** shines! 😉</sub>
38
+ <!-- PyPI -->
39
+ <div align="center">
40
+ <a href="https://brokensrc.dev/"><img src="https://raw.githubusercontent.com/BrokenSource/TurboPipe/main/turbopipe/resources/images/turbopipe.png" width="200"></a>
41
+ <h1>TurboPipe</h1>
42
+ Faster <a href="https://github.com/moderngl/moderngl"><b>ModernGL Buffers</b></a> inter-process data transfers for subprocesses
43
+ <br>
44
+ <br>
45
+ <a href="https://pypi.org/project/turbopipe/"><img src="https://img.shields.io/pypi/v/turbopipe?label=PyPI&color=blue"></a>
46
+ <a href="https://pypi.org/project/turbopipe/"><img src="https://img.shields.io/pypi/dw/turbopipe?label=Installs&color=blue"></a>
47
+ <a href="https://github.com/BrokenSource/TurboPipe"><img src="https://img.shields.io/github/v/tag/BrokenSource/TurboPipe?label=GitHub&color=orange"></a>
48
+ <a href="https://github.com/BrokenSource/TurboPipe/stargazers"><img src="https://img.shields.io/github/stars/BrokenSource/TurboPipe?label=Stars&style=flat&color=orange"></a>
49
+ <a href="https://discord.gg/KjqvcYwRHm"><img src="https://img.shields.io/discord/1184696441298485370?label=Discord&style=flat&color=purple"></a>
50
+ </div>
51
+
52
+ <br>
53
+
54
+ # 🔥 Description
55
+
56
+ > TurboPipe speeds up sending raw bytes from `moderngl.Buffer` objects primarily to `FFmpeg` subprocess
57
+
58
+ The **optimizations** involved are:
59
+
60
+ - **Zero-copy**: Avoid unnecessary memory copies or allocation (intermediate `buffer.read()`)
61
+ - **C++**: The core of TurboPipe is written in C++ for speed, efficiency and low-level control
62
+ - **Chunks**: Write in chunks of 4096 bytes (RAM page size), so the hardware is happy (Unix)
63
+ - **Threaded**:
64
+ - Doesn't block Python code execution, allows to render next frame
65
+ - Decouples the main thread from the I/O thread for performance
66
+
67
+ ✅ Don't worry, there's proper **safety** in place. TurboPipe will block Python if a memory address is already queued for writing, and guarantees order of writes per file-descriptor. Just call `.sync()` when done 😉
68
+
69
+ <br>
70
+
71
+ # 📦 Installation
72
+
73
+ It couldn't be easier! Just install the [**`turbopipe`**](https://pypi.org/project/turbopipe/) package from PyPI:
74
+
75
+ ```bash
76
+ # With pip (https://pip.pypa.io/)
77
+ pip install turbopipe
78
+
79
+ # With Poetry (https://python-poetry.org/)
80
+ poetry add turbopipe
81
+
82
+ # With PDM (https://pdm-project.org/en/latest/)
83
+ pdm add turbopipe
84
+
85
+ # With Rye (https://rye.astral.sh/)
86
+ rye add turbopipe
87
+ ```
88
+
89
+ <br>
90
+
91
+ # 🚀 Usage
92
+
93
+ See also the [**Examples**](https://github.com/BrokenSource/TurboPipe/tree/main/examples) folder for comparisons, and [**ShaderFlow**](https://github.com/BrokenSource/ShaderFlow/blob/main/ShaderFlow/Scene.py) usage of it!
94
+
95
+ ```python
96
+ import subprocess
97
+
98
+ import moderngl
99
+ import turbopipe
100
+
101
+ # Create ModernGL objects
102
+ ctx = moderngl.create_standalone_context()
103
+ buffers = [ctx.buffer(reserve=1920*1080*3) for _ in range(2)]
104
+
105
+ # Make sure resolution, pixel format matches!
106
+ ffmpeg = subprocess.Popen(
107
+ 'ffmpeg -f rawvideo -pix_fmt rgb24 -r 60 -s 1920x1080 -i - -f null -'.split(),
108
+ stdin=subprocess.PIPE
109
+ )
110
+
111
+ # Rendering loop of yours (eg. 1m footage)
112
+ for frame in range(60 * 60):
113
+ buffer = buffers[frame % len(buffer)]
114
+ turbopipe.sync(buffer)
115
+ fbo.read_into(buffer)
116
+ turbopipe.pipe(buffer, ffmpeg.stdin.fileno())
117
+
118
+ # Finalize writing, encoding
119
+ ffmpeg.stdin.close()
120
+ turbopipe.close()
121
+ ffmpeg.wait()
122
+ ```
123
+
124
+ <br>
125
+
126
+ # ⭐️ Benchmarks
127
+
128
+ > [!NOTE]
129
+ > **The tests conditions are as follows**:
130
+ > - The tests are the average of 3 runs to ensure consistency, with 5 GB of the same data being piped
131
+ > - These aren't tests of render speed; but rather the throughput speed of GPU -> CPU -> RAM -> IPC
132
+ > - All resolutions are wide-screen (16:9) and have 3 components (RGB) with 3 bytes per pixel (SDR)
133
+ > - The data is a random noise per-buffer between 128-135. So, multi-buffers runs are a noise video
134
+ > - Multi-buffer cycles through a list of buffer (eg. 1, 2, 3, 1, 2, 3... for 3-buffers)
135
+ > - All FFmpeg outputs are scrapped with `-f null -` to avoid any disk I/O bottlenecks
136
+ > - The `gain` column is the percentage increase over the standard method
137
+ > - When `x264` is Null, no encoding took place (passthrough)
138
+ > - The test cases emoji signifies:
139
+ > - 🐢: Standard `ffmpeg.stdin.write(buffer.read())` on just the main thread, pure Python
140
+ > - 🚀: Threaded `ffmpeg.stdin.write(buffer.read())` with a queue (similar to turbopipe)
141
+ > - 🌀: The magic of `turbopipe.pipe(buffer, ffmpeg.stdin.fileno())`
142
+ >
143
+ > Also see [`benchmark.py`](https://github.com/BrokenSource/TurboPipe/blob/main/examples/benchmark.py) for the implementation
144
+
145
+ ✅ Check out benchmarks in a couple of systems below:
146
+
147
+ 📦 TurboPipe v1.0.4:
148
+
149
+ <details>
150
+ <summary><b>Desktop</b> • (AMD Ryzen 9 5900x) • (NVIDIA RTX 3060 12 GB) • (DDR4 2x32 GB 3200 MT/s) • (Arch Linux)</summary>
151
+ <br>
152
+
153
+ <b>Note:</b> I have noted inconsistency across tests, specially at lower resolutions. Some 720p runs might peak at 2900 fps and stay there, while others are limited by 1750 fps. I'm not sure if it's the Linux EEVDF scheduler, or CPU Topology that causes this. Nevertheless, results are stable on Windows 11 on the same machine.
154
+
155
+ | 720p | x264 | Buffers | Framerate | Bandwidth | Gain |
156
+ |:----:|:----------|:---------:|----------:|------------:|---------:|
157
+ | 🐢 | Null | 1 | 882 fps | 2.44 GB/s | |
158
+ | 🚀 | Null | 1 | 793 fps | 2.19 GB/s | -10.04% |
159
+ | 🌀 | Null | 1 | 1911 fps | 5.28 GB/s | 116.70% |
160
+ | 🐢 | Null | 4 | 857 fps | 2.37 GB/s | |
161
+ | 🚀 | Null | 4 | 891 fps | 2.47 GB/s | 4.05% |
162
+ | 🌀 | Null | 4 | 2309 fps | 6.38 GB/s | 169.45% |
163
+ | 🐢 | ultrafast | 4 | 714 fps | 1.98 GB/s | |
164
+ | 🚀 | ultrafast | 4 | 670 fps | 1.85 GB/s | -6.10% |
165
+ | 🌀 | ultrafast | 4 | 1093 fps | 3.02 GB/s | 53.13% |
166
+ | 🐢 | slow | 4 | 206 fps | 0.57 GB/s | |
167
+ | 🚀 | slow | 4 | 208 fps | 0.58 GB/s | 1.37% |
168
+ | 🌀 | slow | 4 | 214 fps | 0.59 GB/s | 3.93% |
169
+
170
+ | 1080p | x264 | Buffers | Framerate | Bandwidth | Gain |
171
+ |:-----:|:----------|:---------:|----------:|------------:|--------:|
172
+ | 🐢 | Null | 1 | 410 fps | 2.55 GB/s | |
173
+ | 🚀 | Null | 1 | 399 fps | 2.48 GB/s | -2.60% |
174
+ | 🌀 | Null | 1 | 794 fps | 4.94 GB/s | 93.80% |
175
+ | 🐢 | Null | 4 | 390 fps | 2.43 GB/s | |
176
+ | 🚀 | Null | 4 | 391 fps | 2.43 GB/s | 0.26% |
177
+ | 🌀 | Null | 4 | 756 fps | 4.71 GB/s | 94.01% |
178
+ | 🐢 | ultrafast | 4 | 269 fps | 1.68 GB/s | |
179
+ | 🚀 | ultrafast | 4 | 272 fps | 1.70 GB/s | 1.48% |
180
+ | 🌀 | ultrafast | 4 | 409 fps | 2.55 GB/s | 52.29% |
181
+ | 🐢 | slow | 4 | 115 fps | 0.72 GB/s | |
182
+ | 🚀 | slow | 4 | 118 fps | 0.74 GB/s | 3.40% |
183
+ | 🌀 | slow | 4 | 119 fps | 0.75 GB/s | 4.34% |
184
+
185
+ | 1440p | x264 | Buffers | Framerate | Bandwidth | Gain |
186
+ |:-----:|:----------|:---------:|----------:|------------:|---------:|
187
+ | 🐢 | Null | 1 | 210 fps | 2.33 GB/s | |
188
+ | 🚀 | Null | 1 | 239 fps | 2.64 GB/s | 13.84% |
189
+ | 🌀 | Null | 1 | 534 fps | 5.91 GB/s | 154.32% |
190
+ | 🐢 | Null | 4 | 219 fps | 2.43 GB/s | |
191
+ | 🚀 | Null | 4 | 231 fps | 2.56 GB/s | 5.64% |
192
+ | 🌀 | Null | 4 | 503 fps | 5.56 GB/s | 129.75% |
193
+ | 🐢 | ultrafast | 4 | 141 fps | 1.56 GB/s | |
194
+ | 🚀 | ultrafast | 4 | 150 fps | 1.67 GB/s | 6.92% |
195
+ | 🌀 | ultrafast | 4 | 226 fps | 2.50 GB/s | 60.37% |
196
+ | 🐢 | slow | 4 | 72 fps | 0.80 GB/s | |
197
+ | 🚀 | slow | 4 | 71 fps | 0.79 GB/s | -0.70% |
198
+ | 🌀 | slow | 4 | 75 fps | 0.83 GB/s | 4.60% |
199
+
200
+ | 2160p | x264 | Buffers | Framerate | Bandwidth | Gain |
201
+ |:-----:|:----------|:---------:|----------:|------------:|---------:|
202
+ | 🐢 | Null | 1 | 81 fps | 2.03 GB/s | |
203
+ | 🚀 | Null | 1 | 107 fps | 2.67 GB/s | 32.26% |
204
+ | 🌀 | Null | 1 | 213 fps | 5.31 GB/s | 163.47% |
205
+ | 🐢 | Null | 4 | 87 fps | 2.18 GB/s | |
206
+ | 🚀 | Null | 4 | 109 fps | 2.72 GB/s | 25.43% |
207
+ | 🌀 | Null | 4 | 212 fps | 5.28 GB/s | 143.72% |
208
+ | 🐢 | ultrafast | 4 | 59 fps | 1.48 GB/s | |
209
+ | 🚀 | ultrafast | 4 | 67 fps | 1.68 GB/s | 14.46% |
210
+ | 🌀 | ultrafast | 4 | 95 fps | 2.39 GB/s | 62.66% |
211
+ | 🐢 | slow | 4 | 37 fps | 0.94 GB/s | |
212
+ | 🚀 | slow | 4 | 43 fps | 1.07 GB/s | 16.22% |
213
+ | 🌀 | slow | 4 | 44 fps | 1.11 GB/s | 20.65% |
214
+
215
+ </details>
216
+
217
+ <details>
218
+ <summary><b>Desktop</b> • (AMD Ryzen 9 5900x) • (NVIDIA RTX 3060 12 GB) • (DDR4 2x32 GB 3200 MT/s) • (Windows 11)</summary>
219
+ <br>
220
+
221
+ | 720p | x264 | Buffers | Framerate | Bandwidth | Gain |
222
+ |:----:|:----------|:---------:|----------:|------------:|--------:|
223
+ | 🐢 | Null | 1 | 981 fps | 2.71 GB/s | |
224
+ | 🚀 | Null | 1 | 1145 fps | 3.17 GB/s | 16.74% |
225
+ | 🌀 | Null | 1 | 1504 fps | 4.16 GB/s | 53.38% |
226
+ | 🐢 | Null | 4 | 997 fps | 2.76 GB/s | |
227
+ | 🚀 | Null | 4 | 1117 fps | 3.09 GB/s | 12.08% |
228
+ | 🌀 | Null | 4 | 1467 fps | 4.06 GB/s | 47.14% |
229
+ | 🐢 | ultrafast | 4 | 601 fps | 1.66 GB/s | |
230
+ | 🚀 | ultrafast | 4 | 616 fps | 1.70 GB/s | 2.57% |
231
+ | 🌀 | ultrafast | 4 | 721 fps | 1.99 GB/s | 20.04% |
232
+ | 🐢 | slow | 4 | 206 fps | 0.57 GB/s | |
233
+ | 🚀 | slow | 4 | 206 fps | 0.57 GB/s | 0.39% |
234
+ | 🌀 | slow | 4 | 206 fps | 0.57 GB/s | 0.13% |
235
+
236
+ | 1080p | x264 | Buffers | Framerate | Bandwidth | Gain |
237
+ |:-----:|:----------|:---------:|----------:|------------:|--------:|
238
+ | 🐢 | Null | 1 | 451 fps | 2.81 GB/s | |
239
+ | 🚀 | Null | 1 | 542 fps | 3.38 GB/s | 20.31% |
240
+ | 🌀 | Null | 1 | 711 fps | 4.43 GB/s | 57.86% |
241
+ | 🐢 | Null | 4 | 449 fps | 2.79 GB/s | |
242
+ | 🚀 | Null | 4 | 518 fps | 3.23 GB/s | 15.48% |
243
+ | 🌀 | Null | 4 | 614 fps | 3.82 GB/s | 36.83% |
244
+ | 🐢 | ultrafast | 4 | 262 fps | 1.64 GB/s | |
245
+ | 🚀 | ultrafast | 4 | 266 fps | 1.66 GB/s | 1.57% |
246
+ | 🌀 | ultrafast | 4 | 319 fps | 1.99 GB/s | 21.88% |
247
+ | 🐢 | slow | 4 | 119 fps | 0.74 GB/s | |
248
+ | 🚀 | slow | 4 | 121 fps | 0.76 GB/s | 2.46% |
249
+ | 🌀 | slow | 4 | 121 fps | 0.75 GB/s | 1.90% |
250
+
251
+ | 1440p | x264 | Buffers | Framerate | Bandwidth | Gain |
252
+ |:-----:|:----------|:---------:|----------:|------------:|--------:|
253
+ | 🐢 | Null | 1 | 266 fps | 2.95 GB/s | |
254
+ | 🚀 | Null | 1 | 308 fps | 3.41 GB/s | 15.87% |
255
+ | 🌀 | Null | 1 | 402 fps | 4.45 GB/s | 51.22% |
256
+ | 🐢 | Null | 4 | 276 fps | 3.06 GB/s | |
257
+ | 🚀 | Null | 4 | 307 fps | 3.40 GB/s | 11.32% |
258
+ | 🌀 | Null | 4 | 427 fps | 4.73 GB/s | 54.86% |
259
+ | 🐢 | ultrafast | 4 | 152 fps | 1.68 GB/s | |
260
+ | 🚀 | ultrafast | 4 | 156 fps | 1.73 GB/s | 3.02% |
261
+ | 🌀 | ultrafast | 4 | 181 fps | 2.01 GB/s | 19.36% |
262
+ | 🐢 | slow | 4 | 77 fps | 0.86 GB/s | |
263
+ | 🚀 | slow | 4 | 79 fps | 0.88 GB/s | 3.27% |
264
+ | 🌀 | slow | 4 | 80 fps | 0.89 GB/s | 4.86% |
265
+
266
+ | 2160p | x264 | Buffers | Framerate | Bandwidth | Gain |
267
+ |:-----:|:----------|:---------:|----------:|------------:|--------:|
268
+ | 🐢 | Null | 1 | 134 fps | 3.35 GB/s | |
269
+ | 🚀 | Null | 1 | 152 fps | 3.81 GB/s | 14.15% |
270
+ | 🌀 | Null | 1 | 221 fps | 5.52 GB/s | 65.44% |
271
+ | 🐢 | Null | 4 | 135 fps | 3.36 GB/s | |
272
+ | 🚀 | Null | 4 | 151 fps | 3.76 GB/s | 11.89% |
273
+ | 🌀 | Null | 4 | 220 fps | 5.49 GB/s | 63.34% |
274
+ | 🐢 | ultrafast | 4 | 66 fps | 1.65 GB/s | |
275
+ | 🚀 | ultrafast | 4 | 70 fps | 1.75 GB/s | 6.44% |
276
+ | 🌀 | ultrafast | 4 | 82 fps | 2.04 GB/s | 24.31% |
277
+ | 🐢 | slow | 4 | 40 fps | 1.01 GB/s | |
278
+ | 🚀 | slow | 4 | 43 fps | 1.09 GB/s | 9.54% |
279
+ | 🌀 | slow | 4 | 44 fps | 1.10 GB/s | 10.15% |
280
+
281
+ </details>
282
+
283
+ <details>
284
+ <summary><b>Laptop</b> • (Intel Core i7 11800H) • (NVIDIA RTX 3070) • (DDR4 2x16 GB 3200 MT/s) • (Windows 11)</summary>
285
+ <br>
286
+
287
+ <b>Note:</b> Must select NVIDIA GPU on their Control Panel instead of Intel iGPU
288
+
289
+ | 720p | x264 | Buffers | Framerate | Bandwidth | Gain |
290
+ |:----:|:----------|:---------:|----------:|------------:|--------:|
291
+ | 🐢 | Null | 1 | 786 fps | 2.17 GB/s | |
292
+ | 🚀 | Null | 1 | 903 fps | 2.50 GB/s | 14.91% |
293
+ | 🌀 | Null | 1 | 1366 fps | 3.78 GB/s | 73.90% |
294
+ | 🐢 | Null | 4 | 739 fps | 2.04 GB/s | |
295
+ | 🚀 | Null | 4 | 855 fps | 2.37 GB/s | 15.78% |
296
+ | 🌀 | Null | 4 | 1240 fps | 3.43 GB/s | 67.91% |
297
+ | 🐢 | ultrafast | 4 | 484 fps | 1.34 GB/s | |
298
+ | 🚀 | ultrafast | 4 | 503 fps | 1.39 GB/s | 4.10% |
299
+ | 🌀 | ultrafast | 4 | 577 fps | 1.60 GB/s | 19.37% |
300
+ | 🐢 | slow | 4 | 143 fps | 0.40 GB/s | |
301
+ | 🚀 | slow | 4 | 145 fps | 0.40 GB/s | 1.78% |
302
+ | 🌀 | slow | 4 | 151 fps | 0.42 GB/s | 5.76% |
303
+
304
+ | 1080p | x264 | Buffers | Framerate | Bandwidth | Gain |
305
+ |:-----:|:----------|:---------:|----------:|------------:|--------:|
306
+ | 🐢 | Null | 1 | 358 fps | 2.23 GB/s | |
307
+ | 🚀 | Null | 1 | 427 fps | 2.66 GB/s | 19.45% |
308
+ | 🌀 | Null | 1 | 566 fps | 3.53 GB/s | 58.31% |
309
+ | 🐢 | Null | 4 | 343 fps | 2.14 GB/s | |
310
+ | 🚀 | Null | 4 | 404 fps | 2.51 GB/s | 17.86% |
311
+ | 🌀 | Null | 4 | 465 fps | 2.89 GB/s | 35.62% |
312
+ | 🐢 | ultrafast | 4 | 191 fps | 1.19 GB/s | |
313
+ | 🚀 | ultrafast | 4 | 207 fps | 1.29 GB/s | 8.89% |
314
+ | 🌀 | ultrafast | 4 | 234 fps | 1.46 GB/s | 22.77% |
315
+ | 🐢 | slow | 4 | 62 fps | 0.39 GB/s | |
316
+ | 🚀 | slow | 4 | 67 fps | 0.42 GB/s | 8.40% |
317
+ | 🌀 | slow | 4 | 74 fps | 0.47 GB/s | 20.89% |
318
+
319
+ | 1440p | x264 | Buffers | Framerate | Bandwidth | Gain |
320
+ |:-----:|:----------|:---------:|----------:|------------:|--------:|
321
+ | 🐢 | Null | 1 | 180 fps | 1.99 GB/s | |
322
+ | 🚀 | Null | 1 | 216 fps | 2.40 GB/s | 20.34% |
323
+ | 🌀 | Null | 1 | 264 fps | 2.92 GB/s | 46.74% |
324
+ | 🐢 | Null | 4 | 178 fps | 1.97 GB/s | |
325
+ | 🚀 | Null | 4 | 211 fps | 2.34 GB/s | 19.07% |
326
+ | 🌀 | Null | 4 | 250 fps | 2.77 GB/s | 40.48% |
327
+ | 🐢 | ultrafast | 4 | 98 fps | 1.09 GB/s | |
328
+ | 🚀 | ultrafast | 4 | 110 fps | 1.23 GB/s | 13.18% |
329
+ | 🌀 | ultrafast | 4 | 121 fps | 1.35 GB/s | 24.15% |
330
+ | 🐢 | slow | 4 | 40 fps | 0.45 GB/s | |
331
+ | 🚀 | slow | 4 | 41 fps | 0.46 GB/s | 4.90% |
332
+ | 🌀 | slow | 4 | 43 fps | 0.48 GB/s | 7.89% |
333
+
334
+ | 2160p | x264 | Buffers | Framerate | Bandwidth | Gain |
335
+ |:-----:|:----------|:---------:|----------:|------------:|--------:|
336
+ | 🐢 | Null | 1 | 79 fps | 1.98 GB/s | |
337
+ | 🚀 | Null | 1 | 95 fps | 2.37 GB/s | 20.52% |
338
+ | 🌀 | Null | 1 | 104 fps | 2.60 GB/s | 32.15% |
339
+ | 🐢 | Null | 4 | 80 fps | 2.00 GB/s | |
340
+ | 🚀 | Null | 4 | 94 fps | 2.35 GB/s | 17.82% |
341
+ | 🌀 | Null | 4 | 108 fps | 2.70 GB/s | 35.40% |
342
+ | 🐢 | ultrafast | 4 | 41 fps | 1.04 GB/s | |
343
+ | 🚀 | ultrafast | 4 | 48 fps | 1.20 GB/s | 17.67% |
344
+ | 🌀 | ultrafast | 4 | 52 fps | 1.30 GB/s | 27.49% |
345
+ | 🐢 | slow | 4 | 17 fps | 0.43 GB/s | |
346
+ | 🚀 | slow | 4 | 19 fps | 0.48 GB/s | 13.16% |
347
+ | 🌀 | slow | 4 | 19 fps | 0.48 GB/s | 13.78% |
348
+
349
+ </details>
350
+ <br>
351
+
352
+ <div align="justify">
353
+
354
+ # 🌀 Conclusion
355
+
356
+ TurboPipe significantly increases the feeding speed of FFmpeg with data, especially at higher resolutions. However, if there's few CPU compute available, or the video is too hard to encode (/slow preset), the gains are insignificant over the other methods (bottleneck). Multi-buffering didn't prove to have an advantage, debugging shows that TurboPipe C++ is often starved of data to write (as the file stream is buffered on the OS most likely), and the context switching, or cache misses, might be the cause of the slowdown.
357
+
358
+ The theory supports the threaded method being faster, as writing to a file descriptor is a blocking operation for python, but a syscall under the hood, that doesn't necessarily lock the GIL, just the thread. TurboPipe speeds that even further by avoiding an unecessary copy of the buffer data, and writing directly to the file descriptor on a C++ thread. Linux shows a better performance than Windows in the same system after the optimizations, but Windows wins on the standard method.
359
+
360
+ Interestingly, due either Linux's scheduler on AMD Ryzen CPUs, or their operating philosophy, it was experimentally seen that Ryzen's frenetic thread switching degrades a bit the single thread performance, which can be _"fixed"_ with prepending the command with `taskset --cpu 0,2` (not recommended at all), comparatively speaking to Windows performance on the same system (Linux 🚀 = Windows 🐢). This can also be due the topology of tested CPUs having more than one Core Complex Die (CCD). Intel CPUs seem to stick to the same thread for longer, which makes the Python threaded method often slightly faster.
361
+
362
+ ### Personal experience
363
+
364
+ On realistically loads, like [**ShaderFlow**](https://github.com/BrokenSource/ShaderFlow)'s default lightweight shader export, TurboPipe increases rendering speed from 1080p260 to 1080p360 on my system, with mid 80% CPU usage than low 60%s. For [**DepthFlow**](https://github.com/BrokenSource/ShaderFlow)'s default depth video export, no gains are seen, as the CPU is almost saturated encoding at 1080p130.
365
+
366
+ </div>
367
+
368
+ <br>
369
+
370
+ # 📚 Future work
371
+
372
+ - Disable/investigate performance degradation on Windows iGPUs
373
+ - Improve the thread synchronization and/or use a ThreadPool
374
+ - Maybe use `mmap` instead of chunks writing on Linux
@@ -0,0 +1,6 @@
1
+ turbopipe/__init__.py,sha256=G5UDJHOgRTkf1viJAKRcsP8eud_2Mx5ToMC9qTqOYZ4,1299
2
+ turbopipe/_turbopipe.cpython-310-darwin.so,sha256=RfwUlp5bMHJ36mpc3bpkf8GM4ccmduL7Td1SF345pG0,43480
3
+ turbopipe-1.2.2.dist-info/License.md,sha256=it5BPGKEP68XuUE54o2wVWR8NeWowkvb5dQO62UPeo8,1075
4
+ turbopipe-1.2.2.dist-info/RECORD,,
5
+ turbopipe-1.2.2.dist-info/WHEEL,sha256=hOAaK59YZpDFgTPhg9LTodpYuGsTbl_oV_gzAp7vxW0,94
6
+ turbopipe-1.2.2.dist-info/METADATA,sha256=wOFE8tKTn_jt4GJJVbWkrIGfJZSQbGUuq-vyMA4z2_E,21819
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: meson
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-macosx_10_9_x86_64