Commit 3a59bdd
committed
Add initial buffer length to the resampler
This commit makes the resampler use a proper ring buffer instead of
using an unbound buffer that only gets clear up when a resampling is
done (which could easily end up in memory issues if the input sampling
rate is much higher than the resampling rate).
This also improves the performance of the resampling buy an average of
20% (on my local machine, your millage might vary), even when the
current implementation now needs to copy the buffer when passed to the
resampling function.
Here are the results of running benchmarks/timeseries/resampling.py for
the old implementation, the new implementation (without doing the
bisection and copying) and the new complete implementation with the
current fixable inefficiencies:
OLD NEW NEW WITH BISECT
resamples=10 samples=10 resamples=10 samples=10 resamples=10 samples=10
0.0008896420185919851 0.00062773801619187 0.0008012260077521205
resamples=10 samples=100 resamples=10 samples=100 resamples=10 samples=100
0.007817161997081712 0.005761806009104475 0.006307974021183327
resamples=10 samples=1000 resamples=10 samples=1000 resamples=10 samples=1000
0.07768873398890719 0.05851042701397091 0.0604277040110901
resamples=100 samples=10 resamples=100 samples=10 resamples=100 samples=10
0.008742492995224893 0.0062527229893021286 0.00808265499654226
resamples=100 samples=100 resamples=100 samples=100 resamples=100 samples=100
0.07808284999919124 0.057997508003609255 0.0624066719901748
resamples=100 samples=1000 resamples=100 samples=1000 resamples=100 samples=1000
0.782658567011822 0.5870920980232768 0.6098103950207587
resamples=1000 samples=10 resamples=1000 samples=10 resamples=1000 samples=10
0.08764891701866873 0.062448524025967345 0.07815460601705126
resamples=1000 samples=100 resamples=1000 samples=100 resamples=1000 samples=100
0.78426024899818 0.5858371119829826 0.6357307220168877
resamples=1000 samples=1000 resamples=1000 samples=1000 resamples=1000 samples=1000
7.513815971993608 5.984694316983223 6.42200836900156
Average improvement: 35.3% 19.7%
This commit sadly introduces some nasty hack to be able to bisect the
buffer, we need to make Sample ordered by timestamp because bisect
doesn't support using a key extraction function until Python 3.10.
Signed-off-by: Leandro Lucarella <[email protected]>1 parent 42143f5 commit 3a59bdd
File tree
3 files changed
+47
-39
lines changed- benchmarks/timeseries
- src/frequenz/sdk/timeseries
3 files changed
+47
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
20 | | - | |
21 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
24 | 35 | | |
25 | 36 | | |
26 | 37 | | |
| |||
113 | 124 | | |
114 | 125 | | |
115 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
116 | 135 | | |
117 | 136 | | |
118 | 137 | | |
| |||
306 | 325 | | |
307 | 326 | | |
308 | 327 | | |
309 | | - | |
| 328 | + | |
310 | 329 | | |
311 | 330 | | |
312 | 331 | | |
| |||
316 | 335 | | |
317 | 336 | | |
318 | 337 | | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | 338 | | |
344 | 339 | | |
345 | 340 | | |
| |||
352 | 347 | | |
353 | 348 | | |
354 | 349 | | |
355 | | - | |
356 | | - | |
357 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
358 | 353 | | |
359 | | - | |
360 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
361 | 363 | | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| |||
0 commit comments